例如
String temp = "welcome,to,the,world,of,j2ee";
将此转换为arraylist
ArrayList al= new ArrayList(temp.split(","));
这是arraylist的内容{"welcome","to","the","world","j2ee"}
我的要求是在每个字符串的末尾添加“^ d”
表示前{"welcome^d","to^d","the^d","world^d","j2ee^d"}
答案 0 :(得分:5)
试试这个:
List<String> al= Arrays.asList((temp.replaceAll(",", "^d,") + "^d").split(","));
答案 1 :(得分:1)
在拆分之前,您可以添加^ d。例如:
String temp = "Welcome,to,the,world,of,j2ee";
ArrayList<String> list = Lists.newArrayList(temp.replaceAll(",", "^d,").split(","));
答案 2 :(得分:0)
String.split不返回数组列表,它返回一个常规数组。如果你使用常规数组,那么只需将每个值连接到每个值上。
String temp = "welcome,to,the,world,of,j2ee";
String[] al= temp.split(",");
for(int i = 0; i < al.length; i++){
al[i] += "^d";
}
for(String w : al){
System.out.println(w);
}
答案 3 :(得分:0)
String temp = "welcome,to,the,world,of,j2ee";
temp = (temp + "^d").replace(",", "^d,");
List<String> al= Arrays.asList(temp.split(","));