Can't understand how to return an index number from an ArrayList

Discussion in 'Java' started by trojansc82, Nov 15, 2008.

  1. trojansc82

    trojansc82 New Member

    Joined:
    Nov 15, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm having trouble returning an index number based on a String search. I have a class called CD with a field of tracks. I am trying to search for the track number based on the String I provide.

    Here is the search I have so far:

    Code:
    int index = 0;
    boolean found = false;
    while(index < tracks.size() && !found){
    String track = tracks.get(index);
    if(track.contains(searchString)){
    found = true;
    }
    else{
    index++;
    }
    }
    
    
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice