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: Question about String

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question about String

    hi.. sorry for asking such a noob question.. i am wondering if there anyway in java to give the position of the particular in a String..

    eg:
    for the word: "Java"

    is it possible to say i want to know the position of the letter 'a' in the word.. so for this case it should return 1 and 3...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Question about String

    Look at the API doc for the String class. It has methods that will help you do that.
    Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about String

    i saw that.. the only methods i can think of that help me is the indexOf method.. but it will only return the 1st occurence.. so for my case the last 'a' will be ignore..

    or for case like the word: "Trustworthy"
    the other 2 't' will be ignored??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Question about String

    the indexOf method.. but it will only return the 1st occurence
    There is more than one version of the method.
    One returns the first occurrence
    another will return the next occurrence given a starting point.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Question about String

    ic... thanks alot for answering my noob qn..

Similar Threads

  1. String question
    By pierce21 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 25th, 2012, 05:36 PM
  2. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  3. Question about Scanner and String values
    By cecilg23 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 9th, 2012, 07:58 PM
  4. Question on String class
    By TP-Oreilly in forum Java Theory & Questions
    Replies: 8
    Last Post: September 25th, 2011, 08:12 PM
  5. Java array and string question
    By colerelm in forum Collections and Generics
    Replies: 2
    Last Post: September 14th, 2011, 11:50 PM