The string is
[Ian Wood P. M. Visscher]
[Ian Wood L. Mengersen]
[Ian Wood]
[L. Mengersen Ian Wood]
Ian A. Wood is name of first person followed by a space and then name of second person P. M. Visscher. Similarly for the next string.I want to split the string person wise and store it in an array.For example a[0][0]=Ian Wood , a[0][1]=P. M. Visscher ,a[1][0]=Ian Wood ,a[1][1]=L. Mengersen and so on..Every time when I would give input, the names in the string will change.
How do I split it and store it in the above form in the array.What should I do to get the preferred output?Thank you.
Following is the code I worked on,but does not split properly.
[Ian Wood P. M. Visscher]
[Ian Wood L. Mengersen]
[Ian Wood]
[L. Mengersen Ian Wood]
Ian A. Wood is name of first person followed by a space and then name of second person P. M. Visscher. Similarly for the next string.I want to split the string person wise and store it in an array.For example a[0][0]=Ian Wood , a[0][1]=P. M. Visscher ,a[1][0]=Ian Wood ,a[1][1]=L. Mengersen and so on..Every time when I would give input, the names in the string will change.
How do I split it and store it in the above form in the array.What should I do to get the preferred output?Thank you.
Following is the code I worked on,but does not split properly.
Code:
String[] parts = output.split(" ");
String[][] table = new String[parts.length / 2][2];
for (int i = 0, r = 0; r < table.length; r++) {
table[r][0] = parts[i++];
table[r][1] = parts[i++];
}
System.out.println(java.util.Arrays.deepToString(table));
}
Comment