Monday, 15 December 2014

Java : Collection Framework : HashSet (isEmpty)


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

HashSetExample.java
import java.util.HashSet;

/*
 * Example of isEmpty() method.
 */
public class HashSetExample
{
    public static void main( String[] args )
    {
        HashSet<String> hashSet = new HashSet<String>();

        System.out.println("hashSet: " + hashSet);
        /*
         * Returns true if this set contains no elements.
         */
        boolean isEmpty = hashSet.isEmpty();
        System.out.println("isEmpty :  " + isEmpty + "\n");

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

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

        isEmpty = hashSet.isEmpty();
        System.out.println("isEmpty :  " + isEmpty);

    }
}

Output
hashSet: []
isEmpty :  true

hashSet: [Rohit, Dave, Phil, Peter, Virat]
isEmpty :  false

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