My arraylist consists of an array with a list of strings, each string inside is separated by commas, i want to split one of the strings into substrings divided by the commas, i know how to do it to arrays by using the split method, but im having trouble finding something similar to array lists, heres the code:
String[] widgets2 =
{
"1,John,Smith,John1989@gmail.com,20,88,79,59",
"2,Suzan,Erickson,Erickson_1990@gmailcom,19,91,72,85",
"3,Jack,Napoli,The_lawyer99yahoo.com,19,85,84,87",
"4,Erin,Black,Erin.black@comcast.net,22,91,98,82",
"5,Adan,Ramirez,networkturtle66@gmail.com,100,100,100"
};
ArrayList jim = new ArrayList(Arrays.asList(widgets2));
System.out.println(jim.split(0));
解决方案
It is similar to what you do with the arrays. Just that the implementation is different. To get the values just loop through them:
List jim = new ArrayList(Arrays.asList(widgets2));
for(String currentString : jim){//ArrayList looping
String[] separatedStrings = currentString.split(",");
for(String separatedString : separatedStrings){//Now its array looping
//Do something now whatever you like to
}
}
If you want to have the index and decide which value to get, use normal for loop using index and use jim.get(index) and use split().
Having said that, what stops you from looping through the List ? It's the common usage of array list - to loop through it :)