• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String to Array of String

 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How to convert String to Arrayof String
for Eg. String mstrString ="this is the test string";
after converting
the value of mstrString will be assinged to strArr vaiable.
String strArr[] = { -- value of mstrString --};

i have a String and i want to pass the Array of String into the Array.sort(String[]) methode.

how can i do this ,


Please help me for this
 
pinky yadav
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its not very clear what you want to do actually.
but if you want to convert string to array of string like this

then you can use StringTokenizer which will extract the works for you from the string and then you can put it in array of string.
[ August 11, 2004: Message edited by: pinky yadav ]
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My intenstion is i have a string object and i want to convert this String object into ArrayofString object so that i will pass this ArrayofString object to sort method.

Let us see the Practical scenario
String mstrString = " this is the test string and want to convert it into array of String";
The output is it will return the Array of String
the function looks like

public String[] StringtoArry(String)
{
return String[];
}
}
 
pinky yadav
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want whole string as one entry in array then do


if you want each word as seperate word in array then
 
Santosh Maskar
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Pinky Thanks for the same

I am writing the Webservice and this service will return the nuber of distincet word in the string , i done this by using this
 
Tom Hill
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringTokenizer is a legacy class according to the 1.4.2 API.
You should use String.split(regex).

So to split a sentence up into an array of words:



Hope that helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic