I am still new at java. I have this basic split string function as below. I need to capture the substrings post split. My question is how to move individually split parts into separate variables instead of printing them? Do I need another array to move them separately? Is there another simpler way to achieve this? In part I, for simplicity, I am assuming the delimiters to be spaces. Appreciate your help!
public class SplitString {
public static void main(String[] args) {
String phrase = "First Second Third";
String delims = "[ ]+";
String[] tokens = phrase.split(delims);
String first;
String middle;
String last;
for (int i = 0; i < tokens.length; i++)
{
System.out.println(tokens[i]);
//I need to move first part to first and second part to second and so on
}
}
}
String thirdPart = tokens[2]?