LinkedListSearch.java :  » Location » geo-reminder » tools » Android Open Source

Android Open Source » Location » geo reminder 
geo reminder » tools » LinkedListSearch.java
package tools;

import java.util.LinkedList;
import java.util.ListIterator;

public class LinkedListSearch {

  public LinkedListSearch() {

  }
  
  /**
   * Searches the specified linked list for the specified string
   * and returns the index of the element if found, -1 other wise
   * @param list
   * @param searchStr
   * @return index of element, or -1 if not found
   */
  public int run(LinkedList<String> list, String searchStr){
    
      
    ListIterator<String> itr = list.listIterator();
    
    while(itr.hasNext()){
      if(itr.next().equals(searchStr)){
        return itr.nextIndex();
      }
    }
    
    return -1;
  }
  
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.