Simple HashSet











 This  is  a  simple  example of the HashSet .  This is helpful for beginners .  You must  
  focus   the  program output  which  will make sense  how   HashSet work . Order of 
  insertion  is not maintains here   and     no duplicate  element  present in the output.  




import  java.util.HashSet;
/**
 *
 * @author Mukesh Jha
 *
 */
public class SimpleHasSetexample {

           
            public static void main (String[] args) {
                        // TODO Auto-generated method stub
                        HashSet hSet = new HashSet<>();
                       
                hSet.add(1);
                hSet.add(2);
                hSet.add(3);
                hSet.add(7) ;
                hSet.add(9);
                hSet.add(19);
                hSet.add(20);
                hSet.add(19);
                hSet.add(1);
                hSet.add(20);
                System.out.println("HashSet contains.." + hSet);  
            }

}
-->

 Program  output  :------



HashSet contains..[0, 1, 2, 3, 19, 20, 7, 9]









Simple HashSet Simple HashSet  Reviewed by Mukesh Jha on 3:26 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.