I have a string as [Ian Wood P. M. Visscher]
[Ian Wood L. Mengersen]
[Ian Wood]
[P. M. Visscher Ian Wood].I want to write this string into two dimensional array. (i.e) String 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. Please suggest any idea . Thanks in advance.Following is the code I worked on,but does not split properly.

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));

From your data it looks like a name may be in two parts (Ian Wood) or three (P. M. Vissche), or maybe more? If that's the case you will need some kind of "intelligent" algorithm to decide that it's [Ian Wood] [P. M. Visscher] and not [Ian Wood P.] [M. Visscher], because there's nothing in the data or delimiters that answers that question.

Yes..I have problem in extracting the correct names or i do not know how to get those exact names..Can anyone suggest me with any specific method or algorithm..Because I tried with the various regex expressions but no success.

Is there any way you re-define the input data format so that the two names are separated by a known delimiter (eg [Ian Wood | P. M. Visscher])?

Actually I extracted the names from a web page and stored it in an array called output.And then Im spliting it.The original array is array of arrays like this

{
            {"Ian Wood ","P. M. Visscher"},
            {"Ian Wood"," L. Mengersen"},
            {"Ian Wood"},
            {"P. M. Visscher"," Ian Wood}"
    };


But after when I extract the names I get it as 
[Ian Wood P. M. Visscher]
[Ian Wood L. Mengersen]
[Ian Wood]
[P. M. Visscher Ian Wood]
Now here is where the problem lies.It cannot be split since there are many spaces in the names and initials are separated by a dot..

Why are you trying to split it when you already have it split when you first get it???

There can be more than 2 people together in the array like,

{"Ian Wood ","P. M. Visscher"," L. Mengersen"},{"Ian Wood"," P. M. Visscher"}

.I need to keep only two people in an array at a time like:
[Ian Wood P. M. Visscher]
[Ian Wood L. Mengersen]
[Ian Wood P. M. Visscher]
and then put them in a 2D array...

Just copy the first two from the source array into your target array, and ignore the rest.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.