Monday, 15 December 2014

Java : Collection Framework : HashSet (Size)


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

HashSetExample.java
import java.util.HashSet;

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

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

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

        /*
         * Returns the number of elements in this set (its cardinality).
         */
        int size = hashSet.size();
        
        System.out.println("size : "+size);

    }
}

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

size : 5

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

    Google+ Followers

    Google+ Badge