java8 list 字符串 互转

// string 转 list        
    String idStr = "1,2,3";
    List<Long> listIds = Arrays.asList(idStr.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
    listIds.forEach(System.out::println);
console---------------------------------------------------------
1
2
3
// list 转 string
    List<Long> idList = Arrays.asList(1L, 2L, 3L);
    String idString = String.join(",", idList.stream().map(String::valueOf).collect(Collectors.toList()));
    System.out.println(idString);
console--------------------------------------------------------------------------------
1,2,3

你可能感兴趣的:(操作,java,java)