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: Strings and Characters

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Strings and Characters

    String String1 = new String();

    String1 = "bubble";

    String1.charAt(4);

    I want to input the result of String1.charAt(4); which is the letter l into a method which only takes a char as an argument.

    What line of code is required?


  2. #2
    Member
    Join Date
    Jun 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Strings and Characters

    I tried:

    String1.charAt(4) = char aChar;

    I get: Syntax error: column 21. Encountered: char

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Strings and Characters

    What does the String charAt() method return?
    a method which only takes a char as an argument.
    String1.charAt(4) should work as is.

    What were you trying to do with this: String1.charAt(4) = char aChar;
    It looks reversed from what it should be.

  4. #4
    Member
    Join Date
    Jun 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Strings and Characters

    String1.charAt(4) should work as is. Yes it does, it returns the letter l, but then how do i input this result into another method that only takes a char as an
    argument.

    displayLetter(String1.charAt(4)) wont work , so what coding do i need? How do i assign the result to a value that displayLetter() can take as an argument?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Strings and Characters

    displayLetter(string1.charAt(4)) wont work
    Have you tried it?

    How is displayLetter defined?
    Is it: displayLetter(char c)
    Last edited by Norm; July 4th, 2011 at 05:39 PM.

  6. #6
    Member
    Join Date
    Jun 2011
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Strings and Characters

    displayLetter(String1.charAt(4)) actually does work!!

    cheers

Similar Threads

  1. Strings and Characters
    By av8 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: July 3rd, 2011, 03:21 PM
  2. [SOLVED] characters per line in Eclipse
    By joon in forum Java IDEs
    Replies: 1
    Last Post: June 20th, 2011, 07:47 AM
  3. [SOLVED] Characters per line in Eclipse
    By joon in forum Java Theory & Questions
    Replies: 2
    Last Post: June 18th, 2011, 04:41 PM
  4. finding unescaped XML characters
    By diptee in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 18th, 2010, 04:51 AM
  5. How to check whether the string contains only the specified characters ????
    By j_kathiresan in forum Java Theory & Questions
    Replies: 3
    Last Post: April 30th, 2010, 08:49 AM