Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to read a string into an array?

  1. #1
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default How to read a string into an array?

    x


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to read a string into an array?

    Look at the split() method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to read a string into an array?

    split() is a String method. It is used in lots of code posted on the forum. Do a search for some examples.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to read a string into an array?

    The are many examples given in the API doc for the split() method that use simple Strings.
    Look at some of them and see if the String you want to split has anything like what the examples show.

    regex stands for regular expression. That's something you'll not want to worry about for a while.

    Did you try the simple example you found? What happened?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to read a string into an array?

    There are lots of tutorials on how to write regular expressions. Follow the links in the String class's API doc
    and ask google.

    do I type "regex" or is that a descriptive placeholder representing the actual delimter I wish to use?
    The API doc shows that the arg to the split method is a String named regex. Read the API doc for a description of the variable: regex in the Parameters: section.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How to read a string into an array?

    An easy way to see array contents:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    javaiscool (March 26th, 2013)

Similar Threads

  1. Replies: 3
    Last Post: March 23rd, 2013, 07:20 PM
  2. How to read a String .dat file into an array
    By Wallatrix in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 5th, 2013, 02:55 PM
  3. [SOLVED] Sorting an object array using string variables from a string array
    By Shadud in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 26th, 2012, 05:50 PM
  4. HW-how to read a string from a text file
    By yaboibangz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2012, 09:34 AM
  5. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM