2dimensional array

Hi,

Please help me in solving this....

I have got a 2 dimensional string as String [ ] [ ] str = null;

and it contains the strings as follows :

row1 : ABCD~adfg~yuio~

row2 : sfdfk~sdf~ds~sad~

row3 : sa~dk~

now i want to extract each individual string. So i use Stringtokenizer.

now i try to copy it an array...it gives me an error.

StringTokenizer str3 = null;

String [ ] str4 = null;

for (int 1=0;i<=str.length;i++)

{

str2=str[0].trim();

str3 = new StringTokenizer(str2,"~");

while (str3.hasMoreTokens())

{

// copy to a 1D array

str4 = str3.nextToken();

}

}

[698 byte] By [Sundar.nagarathinama] at [2007-11-27 5:58:45]
# 1
As far as I can tell you do not have a 2D array. You have a simple array.String[] str = {"ABCD~adfg~yuio~", "sfdfk~sdf~ds~sad~", "sa~dk~"};
floundera at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 2
no its a 2 dimensional array......
Sundar.nagarathinama at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 3
> it gives me an error.What error?And what code gives that error? (Please use the "code" tags described here: http://forum.java.sun.com/help.jspa?sec=formatting)
pbrockway2a at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 4
> no its a 2 dimensional array......You maybe using a 2D array but from the code snippet you posted (please use code tags in future, see the code button) your data is not a 2D array and can be implemented as I have shown.
floundera at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 5
The code posted really doesn't show much. It gets off to a shaky start with the =null business, but then collapses completely after we get to 1=0.What is the actual error, and some actual code to generate it?
pbrockway2a at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 6
sorry its actually i = 1;i want to extract individual strings separated by ~ in a two dimensional string array and need to put those extracted strings in an one dimensional array....
Sundar.nagarathinama at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 7

>i want to extract individual strings separated by ~ in a two dimensional string array and need to put those extracted strings in an one dimensional array....

do you mean 1D to 2D array?

from:

{ "ABCD~adfg~yuio~", "sfdfk~sdf~ds~sad~", "sa~dk~ ... }

to:

{ {"ABCD", "adfg", "yuio"},

{"sfdfk", "sdf"... } }

Message was edited by:

j_shadinata

j_shadinataa at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 8
no....2d to 1D
Sundar.nagarathinama at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 9
Post your actual code, surrounded by [code] [/code], the actual error messages and indicate on which lines the errors are.
floundera at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...
# 10
well, you do declare your input is 2D array.String[][] str = null;but you use it as 1D array.str2=str[0].trim();if it's 2D then the code will str2 = str[0][0].trim();
j_shadinataa at 2007-7-12 16:34:11 > top of Java-index,Java Essentials,New To Java...