Java – converts comma separated values to lists

Suppose I have a set of numbers, such as 1,2,3,4,5,6,7 inputs as a string I want to convert these numbers into a long object list, that is, list < long >

Can anyone recommend the simplest way?

Solution

I will use the excellent Google guava library to do this String. Split can cause a lot of trouble

String numbers="1,7";
Iterable<String> splitIterator = Splitter.on(',').split(numbers);
List<String> list= Lists.newArrayList(splitIterator );
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>