Results 1 to 4 of 4
  1. #1
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Find the index number of strings in an arraylist

    I have an arraylist with strings inside it. I want to find out the specific index number each item is sitting on. I am thinking of using a for loop. What method can I use on the variable I call on the variable I declare my for loop.

    Java Code:
    for(String v : myArrayObject){
    System.out.println(v.someMethodToFindIndex + v);
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by africanhacker View Post
    I have an arraylist with strings inside it. I want to find out the specific index number each item is sitting on. I am thinking of using a for loop. What method can I use on the variable I call on the variable I declare my for loop.

    Java Code:
    for(String v : myArrayObject){
    System.out.println(v.someMethodToFindIndex + v);
    }
    Use an ordinary loop so you have your index value available at all times:

    Java Code:
    for (int i= 0; i < myArrayObject.size(); i++) {
       String s= myArrayObject.get(i);
       // String s is stored at position i ...
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    africanhacker is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Cheers man.

    Out of curiosity what do you guys do. You seem to be always available to answer questions? Are you like freelance or are you somehow affiliated with this website?

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by africanhacker View Post
    Cheers man.

    Out of curiosity what do you guys do. You seem to be always available to answer questions? Are you like freelance or are you somehow affiliated with this website?
    Yep, I'm self employed and I refresh my window to this forum now and then; I'm not affiliated with this forum whatsover.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 6
    Last Post: 03-24-2011, 04:01 AM
  2. Finding maximum number at index position
    By Shyamz1 in forum New To Java
    Replies: 9
    Last Post: 10-27-2010, 08:14 PM
  3. Replies: 12
    Last Post: 11-05-2009, 07:12 AM
  4. Find index position of every word in a String
    By pentace in forum New To Java
    Replies: 6
    Last Post: 06-28-2009, 08:26 PM
  5. getting strings from arraylist
    By Ms.Ranjan in forum New To Java
    Replies: 15
    Last Post: 05-06-2009, 10:40 PM

Posting Permissions

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