Reputation: 76
I was wondering if the following code converts a list with string values to a list of integer values?
Example of what I want : ['14','15','67']
---> [14,15,67]
String s = strLine;
List myList = new ArrayList<String>(Arrays.asList(s.split(" ")));
List<Integer> intList = myList;
Or do I need to iterate over it using a for loop?
Upvotes: 0
Views: 89
Reputation: 6070
Java keeps a tight ship. You need to try and parse the String
s into integers:
List<Integer> intList = new List<Integer>();
for (String s : strList) {
intList.add(Integer.parseInt(s));
}
Upvotes: 3