1.string转数组
例:String :“1,2,3”
String str = "1,2,3";
//转成string类型的数组
List<String> list = Arrays.asList(str.split(","));
//转成Integer类型的数组
int[] ints = list.stream().mapToInt(Integer::parseInt).toArray();
List<Integer> ids = Arrays.stream(ints).boxed().collect(Collectors.toList());
结果:
[1, 2, 3]
[1, 2, 3]
2.数组转成逗号隔开的string
方法一:
String str = Arrays.stream(issueIds).map(Objects::toString).collect(Collectors.joining(","));
方法二:
String s = list.stream().map(Objects::toString).collect(Collectors.joining(","));
方法三:使用谷歌的Joiner转换
public static <T> String parseListToStr(List<T> list){
String result = Joiner.on(",").join(list);
return result;
}
结果:
1,2,3