Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert Char array to two dimensional string

 
prazannag Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
prazannag Kumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember there is no such thing as a 2D array. A String[][] is not a 2D array, but an array of arrays of Strings.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic