Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create Ragged Array with String.Split

807580Jun 9 2010 — edited Jun 11 2010
I am trying to create a ragged array from a TAB delimited file using String.split. The basic data consists of numerous strings separated by TAB(\t) and each line terminates with a newline(\n);

the logic is:
//buffer = String with the Tab Delimited data:
//            "abcd\tdefgh\tijk\nabcd\tdefgh\tijk\n"

String [][] array;
String[] tmp;

tmp = buffer.split("\n");                    // {color:#ff0000}produces an array with two elements{color}
array = new String[ tmp.length ][150];
for (int x = 0; x < tmp.length; x++) {
    array[x] = tmp[x].split("\t");         // {color:#ff0000}does not produce any results, array[x].length is 0{color}
}
The first split (buffer.split) correctly splits the data into the proper number of data lines. The second split (tmp[x].split) apparenlty fails to produce any results, there is no array created. I am at a loss as to what is going on. Any help would be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 9 2010
Added on Jun 9 2010
5 comments
264 views