GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes How to convert Char array to two dimensional string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert Char array to two dimensional string" Watch "How to convert Char array to two dimensional string" New topic
Author

How to convert Char array to two dimensional string

prazannag Kumar
Greenhorn

Joined: Feb 25, 2010
Posts: 12
Hi,

I mess with converting the char array to two dimensional array in android. Anyone can clarify this issue ? Is it possible to do the conversion mentioned below ?

String[][] s = new String[3][3];
static char tmp[5] = "hello";
int r=1,c=1,j;
for( j=0;j<5;j++)
{
s[r][c].charAt(j)=tmp[j];
}
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

1. What does this question has to do with Android??
2. There are too many problems with your code. It will fail compilation at several locations. Even after correcting the errors, the logic doesn't seems right to me. I'm not even sure what exactly you are trying to achieve. How do you want to distribute the 1-D char array to a 2-D String array??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
prazannag Kumar
Greenhorn

Joined: Feb 25, 2010
Posts: 12
I ll explain my problem,
My Input is: "this is my first program"
then I have to split each word and to store on different string . It can be possible with 1D string array. suppose if i need to perform this on 2D string array,how to do? please let me know.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

prazannag Kumar wrote:suppose if i need to perform this on 2D string array,how to do?

This is exactly my question, how do you want to spread the words in a 2D string array?? You are saying that the input is "this is my first program", so now how do you want to spread it across a 2D string array?? Do you want 3 words in each row of the String array?? So basically the String array would become
thisismy
firstprogram

Since converting char[] to String[][] is all you want, so I'm move this question to Beginning Java forum...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39053
    
  23
Remember there is no such thing as a 2D array. A String[][] is not a 2D array, but an array of arrays of Strings.
 
GeeCON Prague 2014
 
subject: How to convert Char array to two dimensional string