• Post Reply Bookmark Topic Watch Topic
  • New Topic

String to Strin[] conversion  RSS feed

 
Kajol Singh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am trying to convert a String to String[].
String a = "abc";
String[] temp = (String[]) a;
What am I doing wrong here?
Thanks,
Kaj
 
Craig Demyanovich
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want an array of characters? If so, try the toCharArray() method of the String class.
Do you want an array of Strings, the first of which is equal to "abc"? If so, first create the String array, declaring the desired number of items it will hold, then set the 0th item to "abc" or a variable that contains it.

Or, try this

Or, if you need a container with a variable amount of storage, have a look at the collections classes in the java.util package.
Or, do you want something else?
Finally, this post is off-topic for the J2EE forum. In the future, please find the most appropriate forum and post to it; there are many from which to choose.
HTH,
Craig
[ August 28, 2002: Message edited by: Craig Demyanovich ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!