I am stuck splitting a string into pieces to store the pieces into an ArrayList. I can split the string onto " ", but I’d like to split the string onto "farmersmarket" and store it into an Arraylist. To be able to return one of the indexed pieces of string.
ArrayList<String> indexes = new ArrayList<String>();
String s = file;
for(String substring: s.split(" ")){
indexes.add(substring);
}
System.out.println(indexes.get(2));
Any ideas to split a string on "farmersmarket"?
And afterwards you don’t need an
Arraylistto get a specific element of the tokens. You can access every token like thisIf you need a
Listyou can doand if it has to be an
Arraylistdo