Convert String to List<Integer>

 

String ids = new String("111,22,33,44");

String[] items = ids.split(",");
List<Integer> appIdList = Stream.of(items).map(Integer::parseInt).collect(Collectors.toList());

By constructing a stream, using the intermediate method map of the stream to convert String -> Integer, and finally outputting the list using the end method of the stream.

 

 

Guess you like

Origin blog.csdn.net/kqZhu/article/details/107691402