How to convert String[] values to List<Long>

by (262 points)
+1 vote
I am using csv reader to read a file and stoing array of strings in a value, how to convert those to list<long>.

Please provide some example.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes

If you are targeting Java 8 (or later), you can try this:

String[] numbers = new String[] {1, 2, 3, 4};
List<Long> longs = Arrays.stream(numbers)
Hope above example helps.
asked Nov 16, 2016 by (262 points)
retagged May 14, 2018 by
Is any other option to covert in java 7?