所以我有这个代码用于使用 mediastore 获取图像:
int dataIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA );
mMediaStoreCursor.moveToPosition(position);
String dataString = mMediaStoreCursor.getString(dataIndex);
Uri mediaUri = Uri.parse("file://" + dataString);
return mediaUri;
Run Code Online (Sandbox Code Playgroud)
这很好地获取图片文件夹中的所有图像,我想更改它以获取特定文件夹中的所有图像,该文件夹将作为字符串传递。例如{ android/picture/specificfolder/}
如何构造一个条件,如果短语的名称为"x",则在显示短语时忽略"x"?
例:
if(item.contains("Text"))
{
//Then ignore "Text" and display the remaining mill
}
Run Code Online (Sandbox Code Playgroud) 我正在研究一种将二进制数字转换为其相应的单词值的代码。
例如,我输入“3”,代码会将数字转换为“11”,这是“3”的二进制表示形式。该代码将继续将“11”转换为“一一”并输出。
我已经写了二进制转换部分,但我很难将其转换为单词。
public class BinaryWords {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String S = sc.nextLine(); //how many times the for loop will repeat
for (int i = 0; i < S.length() + 1; i++) {
int A = sc.nextInt(); //input the number
String convert = Integer.toBinaryString(A); //converts the number to binary String
String replace = convert.replaceAll("[1 0]", "one, zero "); //replaces the String to its value in words …Run Code Online (Sandbox Code Playgroud) Array.mapJava中是否有相当于Javascript的东西?
我一直在玩Java 8:
List<Long> roleList = siteServiceList.stream()
.map(s -> s.getRoleIdList()).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但这不起作用我不知道为什么警告说Incompatible Type.
我怎么能在Java8中这样做?
我正在使用实体的lombok项目这是我的例子:
package com.company.entities;//<---------Note the package
import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Entity
@Builder
@Getter @Setter @AllArgsConstructor @NoArgsConstructor @ToString
public class Client {
@Id
private long id;
private String firstName;
private String lastName;
}
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试在同一个包中使用时,它工作正常:
当我将包更改为例如package com.company.controllers;:
package com.company.controllers;//<---------Note the package
public class Mcve {
public static void main(String[] args) {
Client client = new Client.ClientBuilder()
.id(123)
.firstName("firstName")
.lastName("lastName")
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
ClientBuilder() is not public in com.company.entities.Client.ClientBuilder; cannot be accessed from …Run Code Online (Sandbox Code Playgroud) 我用@Builder的龙目岛的项目,所以我认为有这样的例子:
@Builder
public class Client {
private @Getter @Setter Integer id;
private @Getter @Setter String name;
}
Run Code Online (Sandbox Code Playgroud)
这相当于:
public class Client {
private @Getter @Setter Integer id;
private @Getter @Setter String name;
public static class Builder {
private Integer id;
private String name;
private Builder() {
}
public Builder id(final Integer value) {
this.id = value;
return this;
}
public Builder name(final String value) {
this.name = value;
return this;
}
public Client build() {
return …Run Code Online (Sandbox Code Playgroud) 我有ArrayList这样的:
var amplititudes : ArrayList<Int> = ArrayList()
Run Code Online (Sandbox Code Playgroud)
我想用随机的Ints来填充它.我怎样才能做到这一点?
我使用正则表达式从名称中删除特殊字符.该表达式将删除除英文字母之外的所有字母.
public static void main(String args[]) {
String name = "Özcan Sevim.";
name = name.replaceAll("[^a-zA-Z\\s]", " ").trim();
System.out.println(name);
}
Run Code Online (Sandbox Code Playgroud)
输出:
zcan Sevim
Run Code Online (Sandbox Code Playgroud)
预期产出:
Özcan Sevim
Run Code Online (Sandbox Code Playgroud)
我得到了不好的结果,因为我这样做,正确的方法是删除基于ASCII码的特殊字符,以便其他字母不会被删除,有人可以帮助我使用只删除特殊字符的正则表达式.
我有代码:
static void doSmth() {
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 30; i++) {
list.add(String.valueOf(i));
}
list.stream().filter("1329"::contains).map(s -> s + "a").forEach(System.out::println);
}
Run Code Online (Sandbox Code Playgroud)
为什么我得到:
1a
2a
3a
9a
13a
29a
Run Code Online (Sandbox Code Playgroud)
我期望输出为空,因为列表不包含“ 1329”。
我有数据库中的这些示例记录,这是按查询分组的结果:
[
{
"name": "Troy",
"acct": 1123,
"type": " Savings",
"total": 50
},
{
"name": "Larry",
"acct": 4233,
"type": " Savings",
"total": 200
},
{
"name": "Troy",
"acct": 1123,
"type": " Current",
"total": 120
},
{
"name": "Larry",
"acct": 4233,
"type": " Current",
"total": 220
}
]
Run Code Online (Sandbox Code Playgroud)
现在,我需要创建一个如下所示的报告:
[
{
"name": "Troy",
"acct": 1123,
"totalSavings": 50,
"totalCurrent": 120
},
{
"name": "Larry",
"acct": 4233,
"totalSavings": 200,
"totalCurrent": 220
}
]
Run Code Online (Sandbox Code Playgroud)
。
public class DbTrans {
private String name;
private String …Run Code Online (Sandbox Code Playgroud) java ×10
java-8 ×3
string ×3
java-stream ×2
lambda ×2
lombok ×2
regex ×2
android ×1
binary ×1
entity ×1
if-statement ×1
jpa ×1
kotlin ×1
mediastore ×1
replace ×1