wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes String to String array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String to String array" Watch "String to String array" New topic
Author

String to String array

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I have String abc = "Hello this is test"
I want to store String into String Array called
String [] xyx = new String[abc.length()]
How can I do?
Thanks in advance
angela
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
Try this....

hth
Pat B.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Do you mean one character at a time???
String abc = "Hello this is test";
String [] xyx = new String[abc.length()];
for ( i=0 ; i < abc.length() ; i++ ){
xyx[i] = abc.substring( i , i + 1 );
}


"JavaRanch, where the deer and the Certified play" - David O'Meara
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks to all,,
I am sorry actually i want to ask this
I want to parse following String
ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD
to
ABCDH2001API
0000
1
1
3
2
AB
3
ABC
4
ABCD
without using array and StringTokenizer. Only with the use of substring or startwith or other routines of the string.
Plz help me out,
Thanks
Angela
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Angela,
Have you tried something like this?

Hope this helps.
Stephanie
[This message has been edited by Stephanie Grasson (edited February 27, 2001).]
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks to Cindy and Stephanie,
I don't want to use Array? Plz help me out... ANd Sometime my message can be
String s = "ABCDH2001API:0000: :1:3:2:AB:3:ABC:4:ABCD";
So I can't count on del ":"
plz help me out..
Thanks
Angela

Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Angela,
I am getting a little confused.
You say:

I don't want to use Array

but your original question said:

I want to store String into String Array called
String [] xyx = new String[abc.length()]
How can I do?

Maybe you could explain the question in more detail?
Thanks.
Stephanie
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
I am sorry Stephanie, it's my mistake , Plz don't go for first question(first post) i asked in wrong way.
Plz see second post I have asked....
You have sent me this example:
public static void main(String args[])
{
String s = "ABCDH2001API:0000:1:1:3:2:AB:3:ABC:4:ABCD";
// figure out how many substrings we have
int numColons = 0;
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == ':')
{
numColons++;
}
}
// create an array and parse
String afterParse[] = new String[(numColons + 1)];
int stop = s.indexOf(':');
int num = 0;
while(stop != -1)
{
afterParse[num] = s.substring(0, stop);
s = s.substring((stop + 1), s.length());
num++;
stop = s.indexOf(':');
}
afterParse[num] = s;
// print results
for(int j = 0; j < afterParse.length; j++)
{
System.out.println(afterParse[j]);
}
} }

It works fine.I don't want to use array here.
Thanks again,
Sorry for mistake
Angela
Elisabeth Van
Ranch Hand

Joined: Feb 09, 2001
Posts: 42
Angela,
If I'm understanding your question correctly, you want to print the substrings without using an array.
If that is the case, can you just print out the substrings as you parse them instead of putting them into an array?
Replace afterParse[num] = s; with System.out.println(s);
Just a suggestion in case you were still working on this...couldn't quite tell if you'd gotten your question answered or not.
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks to all,
I got the solution of my question without using String Tokenizer and array.
Angela
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String to String array
 
Similar Threads
Convert Java Array to JavaScript Array.
How to convert byte array to string array ?
passing java string array to javascript
Compare Array with String
convert an array of String to char