convert comma separated string to list without intermediate container

前端 未结 7 2200
误落风尘
误落风尘 2021-01-01 12:36

I need to convert comma separated string to list of integers. For example if I have following string

String numbersArray = \"1, 2, 3, 5, 7, 9,\";
         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 13:23

    Using java 8 Streams:

    List longIds = Stream.of(commaSeperatedString.split(","))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());
    

提交回复
热议问题