hello I have a commaseparated list of string and put into an array.
I ultimately need them as a list of shorts, but the only way I know how to do that is get them as an array of shorts then do array.asList()
String[] stringArray= commaSeparatedString.split("\\s*,\\s*");
How can I get that to an array of shorts so I can throw in a list?
THanks
Well presumably you just need to parse each element. But why not just add them to an ArrayList<Short>
?
List<Short> shortList = new ArrayList<Short>(stringArray.length);
for (int i = 0; i < stringArray.length; i++) {
shortList.add(Short.valueOf(stringArray[i]));
}
(Note that you can't have a list of a primitive type, as Java generics don't support primitive type arguments.)
See more on this question at Stackoverflow