I read a text file and put the data into an ArrayList
of String
.
The data is like
China 12351235123 Korea 123532523 USA 1234123
-
Try this :
// Creation of ArrayList of string
ArrayList obj = new ArrayList();
// arrayList of string
obj.add("China 12351235123");
obj.add("Korea 123532523");
obj.add("USA 12341235123");
Iterator iterator = obj.iterator();
String str;
String[] split_str;
long value;
while (iterator.hasNext()) {
str = iterator.next().toString();
split_str = str.split(" ");
String split_2 = split_str[1];
value = Long.parseLong(split_2);
System.out.println(value);
}
- 热议问题