Joinc

导航

java8 字符串转换 list long Integer

1   
2 String ids= "1,2,3,4,5,6";  
3 List<Long> listIds = Arrays.asList(ids.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());  
4 System.out.println(Arrays.toString(listIds .toArray()));//[1,2,3,3,4,5,6]  

//You can use the Lambda functions of Java 8 to achieve this without looping
//来自:http://stackoverflow.com/questions/19946980/convert-string-to-listlong

posted on 2017-12-29 11:10  Joinc  阅读(15914)  评论(0编辑  收藏  举报