Check if a particular element exists in LinkedList - Java Collection Framework

Java examples for Collection Framework:LinkedList

Description

Check if a particular element exists in LinkedList

Demo Code


import java.util.LinkedList;
 
public class Main {
 
  public static void main(String[] args) {
    LinkedList lList = new LinkedList();
   /*from   w w  w. j a v  a2 s .  co  m*/
    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");
   
     boolean blnElement = lList.contains("4");
   
     if(blnElement)
     {
       System.out.println("LinkedList contains 4");
     }
     else
     {
       System.out.println("LinkedList does not contain 4");
     }
  }
}

Result


Related Tutorials