Thursday, 18 December 2014

Java : Collection Framework : LinkedHashSet (Add object in the LinkedHashSet)


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

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of add(E e) method.
 */
public class LinkedHashSetExample
{
    public static void main( String[] args )
    {
        LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>();
        
        System.out.println("linkedHashSet: " + linkedHashSet + "\n");

        /*
         * Adds the specified element to this set if it is not already present.
         * 
         * If this set already contains the element, the call leaves the set
         * unchanged and returns false.
         */

        boolean isAdded = linkedHashSet.add("Dave");

        System.out.println("isAdded : " + isAdded);
        System.out.println("linkedHashSet: " + linkedHashSet + "\n");   
        
        isAdded = linkedHashSet.add("Dave");

        System.out.println("isAdded : " + isAdded);
        System.out.println("linkedHashSet: " + linkedHashSet);  

    }
}

Output
linkedHashSet: []

isAdded : true
linkedHashSet: [Dave]

isAdded : false
linkedHashSet: [Dave]

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