Tuesday, 23 December 2014

Java : Collection Framework : LinkedHashSet (Check Object exist or not)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=LI231D1PJRc&list=UUhwKlOVR041tngjerWxVccw

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of contains(Object o) method.
 */
public class LinkedHashSetExample
{
    public static void main( String[] args )
    {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();

        linkedHashSet.add("Dave");
        linkedHashSet.add("Peter");
        linkedHashSet.add("Phil");
        linkedHashSet.add("Rohit");
        linkedHashSet.add("Virat");

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

        /*
         * Returns true if this set contains the specified element.
         */
        boolean isExist = linkedHashSet.contains("Peter");
        System.out.println("is 'Peter' Exist : " + isExist);
        
        isExist = linkedHashSet.contains("Juli");
        System.out.println("is 'Juli' Exist : " + isExist);

    }
}

Output
linkedHashSet: [Dave, Peter, Phil, Rohit, Virat]

is 'Peter' Exist : true
is 'Juli' Exist : false

To Download LinkedHashSetDemoContains Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/LinkedHashSetDemoContains.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