Saturday, 1 November 2014

Java : Collection Framework : LinkedList (Check Object Exist or not)


Click here to watch in Youtube : https://www.youtube.com/watch?v=7NJXmmzL9Xc

LinkedListContainsExample.java
import java.util.LinkedList;

/*
 * Example of contains(Object o) method
 */
public class LinkedListContainsExample
{

    public static void main(String[] args)
    {
        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        linkedList.add(200);
        linkedList.add(300);
        linkedList.add(10000);
        linkedList.add(5000);
        linkedList.add(2000);

        System.out.println("linkedList : " + linkedList + "\n");

        boolean isExist;

        /*
         * Returns true if this list contains the specified element.
         */
        isExist = linkedList.contains(5000);

        System.out.println("Is 5000 exist :  " + isExist);

        isExist = linkedList.contains(9000);

        System.out.println("Is 9000 exist :  " + isExist);

    }

}

Output
linkedList : [200, 300, 10000, 5000, 2000]

Is 5000 exist :  true
Is 9000 exist :  false

To Download LinkedListDemoContains Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/LinkedListDemoContains.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment