I have a string like this: "Name foo Modified bar"
I want to split this string and then return only "foo". I have looked into splitting strings and found this:
String nameString = "Name foo Modified bar";
System.out.println(
java.util.Arrays.toString(
nameString.split(" ")
));
Output:
[Name, foo, Modified, bar]
I would like to be able to get "foo" on it's own, as a local variable. Something like this:
String name = output.get(1);
This would work if output was an ArrayList that namestring was split into.
How should I approach getting this result? Should I use the string splitting method I have found or something else? Is there a way to split a string into an arraylist?
Thanks.