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 5 of 5

Thread: How to read letters from a word into an array?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to read letters from a word into an array?

    For my hangman game for class, I need to write each letter of a word into an array. How would I go about this?


  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: How to read letters from a word into an array?

    Is your "word" a String object? And you want to create a char array whose contents correspond to the String?

    Then look at the String.toCharArray() method.

    If this does not help, then tell us exactly what it is that you have and what it is that you want to do.


    Cheers!

    Z

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to read letters from a word into an array?

    The word is a String in an array (finds one word by getting a random word from the array). What I need to happen is that the word (lets use the as an example) to be split into its seperate letters(t-h-e) and written into an array.

    --- Update ---

    for the toCharArray thing that you posted, do I need to name an array in the ()? Or how would I reference the created array? Thanks.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,414
    Thanks
    49
    Thanked 2,214 Times in 2,187 Posts

    Default Re: How to read letters from a word into an array?

    Read the API doc for the String class and its methods. It will help you write the code to use the method.
    If you have questions about the contents of the API doc, copy the doc here and ask the questions.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to read letters from a word into an array?

    String a="abc";

    char c=a.charAt(0);

    System.out.println(c);

Similar Threads

  1. Replies: 1
    Last Post: September 8th, 2012, 04:32 AM
  2. Replies: 5
    Last Post: August 20th, 2012, 01:01 AM
  3. Contain method to read array
    By theaveguy in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 11:32 PM
  4. read a file word by word
    By poornima2806 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 23rd, 2012, 02:14 PM
  5. Reading a text file word by word
    By dylanka in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 21st, 2011, 02:06 PM