Search elements of a List

 
import java.util.LinkedList;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List<String> lList = new LinkedList<String>();
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
    lList.add("2");

    System.out.println(lList.indexOf("2"));

    System.out.println(lList.lastIndexOf("2"));

  }
}
  

Output:


1
5
Home 
  Java Book 
    Runnable examples  

Collection List:
  1. Create a list from an array
  2. Add element to a list at specified index
  3. Append one list to another list
  4. Insert a list at Specified Index
  5. Compare two List objects
  6. Convert Collection to List
  7. Convert a Queue to a List
  8. Convert List to array
  9. Convert List to a Set
  10. Copy List to Vector
  11. Copy one List to Another List
  12. Fill all elements in a list
  13. Fill n Copies of Specified Object
  14. Find maximum element in a List
  15. Find Minimum element in a List
  16. Get element by index
  17. Get Enumeration over List
  18. Get Synchronized List from a List
  19. Get Sub List
  20. Loop a list by Iterator
  21. Loop a list by generic Iterator
  22. Loop a list with using ListIterator
  23. Loop through a ist in reverse direction using ListIterator
  24. Remove an element by value and by index from List
  25. Remove all elements from a List
  26. Remove duplicate items from a List
  27. Remove item from a List while looping
  28. Remove range of elements from a List
  29. Remove user object from a list
  30. Replace an Element of List
  31. Replace all occurrences of specified element in a List
  32. Replace an element in a List using ListIterator
  33. Reverse a List
  34. Reverse order of all elements in a List
  35. Rotate elements of a list
  36. Search a List for an item with contains method
  37. Search elements of a List
  38. Binary Search a Sorted List
  39. Binary Search for a non-existent element in a List
  40. Set to change(replace) the value in a list
  41. Shuffle elements in a List
  42. Shuffle(repeatable) a List
  43. Sort a list
  44. Sort a List in descending order using comparator
  45. Swap elements of List