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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • 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
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:
out.println("<form method = post action = \"../servlet/UpdateTestCG/ \"" + sessionID + ">");

out.println("<input type = text name = \"frenchData\">");
out.println("<input type = submit>");
// here is
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.
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
    Bookmark Topic Watch Topic
  • New Topic