I read a text file and put the data into an ArrayList
of String
.
The data is like
China 12351235123 Korea 123532523 USA 1234123
You can use regex and would be careful that not all that numbers can be in a integer range... so there for the list of longs in the code below
public static void main(String[] args) {
List longList = new ArrayList();
Pattern pattern = Pattern.compile("\\w+([0-9]+)");// regex pattern
for (String string : listOfCountriesAndNumbers) {
Matcher matcher = pattern.matcher(string);
for (int i = 0; i < matcher.groupCount(); i++) {
matcher.find();
longList.add(Long.parseLong(matcher.group()));
}
}
System.out.println(longList);
}