This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Casting to array of Strings

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic