I have an array with 2 data fields in each element:
String[] myArr = {"Bob Marley", "Barbara Newton", "John Smith"};
The first and last names and separated by a tab ("\t"). How would I go about splitting them into two arrays, for example:
String[] firstName = {"Bob", "Barbara", "John"};
String[] lastName = {"Marley", "Newton", "Smith"};
I initially tried split("\t") but that didn't work, and I've tried looking up for similar questions here to no avail.
One thing to note, I am not using ArrayList.
Any help would be immensely appreciated. Thank you in advance.
Code snippet:
public static String[] sortNames(String[] info) {
String[] firstName = new String[info.length];
String[] lastName = new String[info.length];
for(int i = 0; i < info.length; i++) {
firstName[i] = info[i].split("\t");
}
return firstName;
}