Results 1 to 8 of 8
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Help with indexof please...

    When I say indexof() for an ArrayList I get the first occurunce of that object. How can I get all of the occurunces in an ArrayList of a specific object?

    Thank you.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Help with indexof please...

    Do you know how to write a loop?

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Help with indexof please...

    Yes but my knowladge for this purpose is not enough.

    Can you provide a guidence or a simple example ?

    Maybe like starting a new loop everytime with the index I have in an ArrayList over and over again?

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Help with indexof please...

    The API is your friend - there are plenty of methods to let you loop over the items and check for Object equality of said items.
    ArrayList (Java Platform SE 6)

  5. #5
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Help with indexof please...

    I looked at this and couldnt find anything handy. I am trying to learn how to do it correctly as well.

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Help with indexof please...

    Quote Originally Posted by fatabass View Post
    I looked at this and couldnt find anything handy. I am trying to learn how to do it correctly as well.
    Really? Iterator, size, get...none of these don't seem like they would be handy? Break the problem down. Figure out how to loop over the elements, then figure out how to check object equality

  7. #7
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Help with indexof please...

    No sorry, the only way I can think of is that boring looping over getting the index everytime, and starting a new loop until I can't find any other occurunce..

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,353
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help with indexof please...

    Read the entire API documentation for the List interface; especially the part that describes the subList( ... ) method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Printing indexOf line
    By clrgomes in forum New To Java
    Replies: 2
    Last Post: 03-06-2011, 08:30 AM
  2. Help in substring and indexOf function
    By janjong03 in forum New To Java
    Replies: 6
    Last Post: 06-16-2010, 05:43 PM
  3. String indexOf
    By ras_pari in forum Advanced Java
    Replies: 3
    Last Post: 10-07-2009, 07:33 AM
  4. tricky indexOf implementation -- Help!!
    By definewebsites in forum New To Java
    Replies: 3
    Last Post: 12-10-2007, 12:48 AM
  5. Help regarding indexOf
    By gauravj in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 01:12 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
  •