public void test(){
List<String> list= Lists.newArrayList();
list.add("one");
list.add("two");
list.add("three");
list.add("four");
String value="";
for (String s:list){
value=value+"->"+s;
}
System.out.println(value);
/**
* 结果:->one->two->three->four
* 或者是:one->two->three->four->
* 但是需求是:one->two->three->four
* 这样就需要对生成字符串的前或者后做处理(截取)
*/
}
public void test(){
List<String> list= Lists.newArrayList();
list.add("one");
list.add("two");
list.add("three");
list.add("four");
/**
* 用->字符串将list内容连接
* 结果:one->two->three->four,不用做二次处理
*/
String value=Joiner.on("->").join(list);
System.out.println(value);
}
分隔符连接list字符串,不做二次处理Joiner.on("").join()
最新推荐文章于 2023-12-27 17:50:12 发布