• Post Reply Bookmark Topic Watch Topic
  • New Topic

Casting to array of Strings

 
Shuaib Gill
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a form in a servlet. When the user types input and clicks the "submit" button, this request will be passed to another servlet, which saves the request as a String, like this:
// TestCG.java
.
.
.
out.println("<form method = post action = \"../servlet/UpdateTestCG/ \"" + sessionID + ">");

out.println("<input type = text name = \"frenchData\">");
out.println("<input type = submit>");
out.println("</form>");
.
.
.
// here is UpdateTestCG.java
//...
count=1;
String userInput = req.getParameter("frenchData");
// ...
I want to save it as an array of Strings rather than just Strings. How can I do this? When I changed the above String statement to
String[count] userInput=req.getParameter("frenchData");
it gave me an error. How can I change a String to an array of Strings? How do you cast a String to an array of Strings. I want to have my user input stored in an array of strings. Please help.
Thanks,
 
Zkr Ryz
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot do such cast, how can you convert a sigle object
in other which holds multiple objects ???
Well you migth try this:

The userInput array will holds alll the words that were written in the text form input.
You may take a look to the java.util.StringTokenizer
API for more information.
Tell me if it helps
Regards Zkr Ryz
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!