Monday 18 May 2015

How to find does LinkedList contains elements or not

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).


import java.util.LinkedList;

public class ContailsElement {

    public static void main(String[] args) {
       
        LinkedList<String> linkedList = new LinkedList<String>();
       
        linkedList.add("Mumbai");
        linkedList.add("Delhi");
        linkedList.add("Noida");
        linkedList.add("Gao");
        linkedList.add("Patna");
        //print linkedlist
        System.out.println(" Linklist is = "+linkedList);
       
        //Returns true if this list contains the specified element
       
        System.out.println(linkedList.contains("Delhi"));
       
        System.out.println(linkedList.contains("panjab"));
       
    }
   
}

Output:

 Linklist is = [Mumbai, Delhi, Noida, Gao, Patna]

 true

 false

No comments:

Post a Comment