Tuesday, 23 December 2014

Java : Collection Framework : LinkedHashSet (Remove object)


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

LinkedHashSetExample.java
import java.util.LinkedHashSet;

/*
 * Example of remove(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");

        /*
         * Removes the specified element from this set if it is present.
         */

        boolean isRemoved = linkedHashSet.remove("Virat");
        System.out.println("isRemoved : " + isRemoved);

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

    }
}

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

isRemoved : true
linkedHashSet : [Dave, Peter, Phil, Rohit]

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