List<Integer>,List<String>之间互相转换
public class Test { public static void main(String[] args) { List<Integer> integerList = new ArrayList<>(); integerList.add(1); integerList.add(2); integerList.add(3); // List<Integer> 转为 List<String>,注意不要用toString List<String> stringList = integerList.stream().map(String::valueOf).collect(Collectors.toList()); System.out.println("List<Integer> 转为 List<String>=====>" + stringList); //List<String> 转为 String 以逗号分隔 String str = String.join(",", stringList); System.out.println("List<String> 转为 String 以逗号分隔====>" + str); //List<String> 转为 List<Integer> List<Integer> integerList1 = stringList.stream().map(Integer::valueOf).collect(Collectors.toList()); System.out.println("List<String> 转为 List<Integer>====>" + integerList1); } }
下班记得打卡