Results 1 to 15 of 15
  1. #1
    madmax2006 is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Noob here, trying to access index in string

    I'm new to Java and I'm trying to figure out how I could access a particular index in a string

    For example, I have the word Car, and I want to print the letter r, which is in the 3rd index. Is there a way to access it? I've been searching for a little while & have gone through the java.sun site but haven't found anything.

    Thanks for the help ahead of time.:D

    btw, I'm using jGrasp, & Java.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Copy the array into an array, then you can access any index.

    Or else you can directly use the charAt() method on the string object. Keep in mind that charAt() method zero index based.

    Java Code:
            String str = "car";
            System.out.println(str.charAt(2));

  3. #3
    madmax2006 is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    Holy crap, thanks. Where did you find that method?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    From my mind. I'm programming over the years on Java and those things are remember me. That's not a miracle, practice make perfect.

    While working on with Java, try to read the Java doc as well.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    practice, ... and a copy of the API - honestly: you can't write code without these docs open and ready to be consulted.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What I believe is this. Once you working on Java over the years make real change. Because several times we have to read the doc. Actually I refer the doc rarely.

  7. #7
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    Java Platform SE 6

    or you can hunt out whatever version of the jdk you're using. or you can just google "java api" plus the class name.

  8. #8
    marclurr is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    Javadoc is your friend :)

  9. #9
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Quote Originally Posted by pbrockway2 View Post
    practice, ... and a copy of the API - honestly: you can't write code without these docs open and ready to be consulted.
    bullshit, tbh. I never use the API, unless I don't know how to do something for the first time, after using anything once, I know it 4 ever ;)
    I die a little on the inside...
    Every time I get shot.

  10. #10
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Quote Originally Posted by pbrockway2 View Post
    practice, ... and a copy of the API - honestly: you can't write code without these docs open and ready to be consulted.
    I've been programming in Java for 14 years, and I still have the API open at all times. There's no way (for me) to memorize all the exceptions.

  11. #11
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    You don't :o It'll just me in that case - I remember every class and what it does, including exceptions, after using them 1-2 times. :D
    I die a little on the inside...
    Every time I get shot.

  12. #12
    Sylar's Avatar
    Sylar is offline Member
    Join Date
    Mar 2009
    Location
    Odessa, Texas
    Posts
    16
    Rep Power
    0

    Default Try using Eclipse IDE...

    With eclipse you can easily access methods of different classes.

    You dont even have to memorize everything....

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Supamagier View Post
    You don't :o It'll just me in that case - I remember every class and what it does, including exceptions, after using them 1-2 times. :D
    Quote Originally Posted by toadaly
    I've been programming in Java for 14 years, and I still have the API open at all times. There's no way (for me) to memorize all the exceptions.
    Actually memorizing all on Java doc is not an easy task. But when we are working on for a long time on quite similar things, came to our mind next time we used it, isn't it. There are some instance we have to look at it. :)

    toadaly, if you are working on for 14 years on Java, I think you may remember a lot than we. :p I just working on for 5-6 years on Java.

  14. #14
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Me for just 1,5. :o
    I die a little on the inside...
    Every time I get shot.

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Help im a noob.. a super noob on java..
    By critdevil in forum New To Java
    Replies: 12
    Last Post: 03-07-2009, 03:17 AM
  2. Noob
    By nokomis in forum Introductions
    Replies: 2
    Last Post: 03-06-2009, 05:10 PM
  3. Big time NOOB
    By enigmaymee in forum New To Java
    Replies: 7
    Last Post: 01-14-2009, 06:11 PM
  4. Please help a noob :)
    By Bays in forum New To Java
    Replies: 15
    Last Post: 06-17-2008, 06:11 AM
  5. Ah! Help a Java Noob
    By Snejana in forum New To Java
    Replies: 4
    Last Post: 01-24-2008, 03:52 AM

Posting Permissions

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