Results 1 to 2 of 2
  1. #1
    LasseA is offline Member
    Join Date
    Oct 2012
    Rep Power

    Default Converting each word in a string to ArrayList<String> values

    I got a selfcheck exercise saying "Write code to read a line of input from the user and print the words of that line in sorted order, without removing duplicates."

    This is what I've tried, but obviously not working, as it just stores the whole string as one parameter in the arraylist, while it should store each word as an individual parameter in the arraylist.
    Java Code:
    ArrayList<String> theList = new ArrayList<String>();
    		System.out.print("Type a message to sort: ");
    How do I find a way to add each word I type in to the arraylist?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Converting each word in a string to ArrayList<String> values

    Check the API for String, looking for methods that might be useful.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 04-07-2012, 11:55 AM
  2. Converting Arraylist to String array
    By ankit1801 in forum New To Java
    Replies: 3
    Last Post: 03-23-2011, 10:07 AM
  3. Replies: 12
    Last Post: 11-26-2010, 08:33 AM
  4. Replies: 1
    Last Post: 11-04-2010, 06:53 PM
  5. Putting a string into ArrayList<String>
    By k4ff1n34dd1c7 in forum New To Java
    Replies: 5
    Last Post: 03-23-2009, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts