Thursday, 25 December 2014

Java : Collection Framework : LinkedHashSet (clone)


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

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of clone() 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 a shallow copy of this LinkedHashSet instance: the elements
         * themselves are not cloned.
         */
        LinkedHashSet<String> clonedLinkedHashSet = (LinkedHashSet<String>) linkedHashSet.clone();

        System.out.println("clonedLinkedHashSet : " + clonedLinkedHashSet);

    }
}

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

clonedLinkedHashSet : [Dave, Peter, Phil, Rohit, Virat]

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