KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > util > HashSet

java.util
Class HashSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Set<E>
Direct Known Subclasses:
JobStateReasons, LinkedHashSet
See Also:
Top Examples, Source Code, TreeSet, Collections.synchronizedSet(Set), HashMap

public boolean add(E o)
See Also:
AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean add(Object o)
See Also:
AbstractCollection, Set
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1548]Hashset demo
By m_akila2002 { at } yahoo { dot } co { dot } in on 2005/09/26 23:35:11  Rate
import java.util.*; 
  
  
 class Hashsetdemo 
  {  
   public static void main ( String args [  ]  )  
    {  
     HashSet h=new HashSet (  ) ; 
     h.add ( "k" ) ; 
     h.add ( "b" ) ; 
     System.out.println ( h ) ; 
    }  
  } 


public void clear()
See Also:
E, AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Object clone()
See Also:
Cloneable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean contains(Object o)
See Also:
E, AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public HashSet()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public HashSet(int initialCapacity)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[752]Example for hashset, iterator
By Venkateshwar Rao Thota on 2005/10/01 06:02:01  Rate
Example for hashset, iterator...  
  
  
 import java.util.*; 
  
  
 class hs 
  {  
   public static void main ( String [  ]  args )   
    {  
     System.out.println ( "Hello World!" ) ; 
         HashSet set = new HashSet (  ) ;  
     for ( int i=0;i < =10;i++ )  
      {  
       set.add ( new Integer ( i%5 )  ) ;  
      }   
  
  
     System.out.println ( "Hash"+ set ) ;  
   
     Iterator itr = set.iterator (  ) ; 
     int sum = 0; 
  
  
     while  ( itr.hasNext (  )  )  
      {  
        sum +=  (  ( Integer ) itr.next (  )  ) .intValue (  ) ; 
       }  
     System.out.println ( " sum = "+sum ) ; 
    }  
  }  
  
  
 


public HashSet(int initialCapacity,
               float loadFactor)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public HashSet(Collection<? extends E> c)
See Also:
NullPointerException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isEmpty()
See Also:
E, AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Iterator<E> iterator()
See Also:
ConcurrentModificationException, AbstractCollection, Set, Collection, Iterable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[545]HashSetIterator and set.begin cause errors
By davepatrickl { at } hotamil { dot } com on 2005/03/11 02:20:07  Rate
//already have username array decalared and working. just want to know how to iterate through hashset to assign each element to a unique names array 
  
  
   HashSet set = new HashSet (  ) ; 
   for ( int i=0; i < numEntries;i++ )  {  
     set.add (  username [ i ]  ) ; 
        }  
   System.out.println ( "Hash"+ set  ) ; 
   int uniqueNums = set.size (  ) ; 
  
  
      //HashSetIterator and set.begin cause errors 
      for  (  HashSetIterator i = set.begin (  ) ; !i.atEnd (  ) ; i.advance (  )   )  
  {  
      System.out.println (  i.get (  )   ) ; 
  } 


[1718]HashSetIterator example from Standford/Duke website doesnt work?
By Anonymous on 2006/03/09 01:40:37  Rate
In this example code:   
  
  
 public HashSet getCandidates ( int i,int j )  
      {  
         HashSet listCandidates = new HashSet ( 9 ) ; 
          
         for  ( HashSetIterator i=candidates [ i ]  [ j ] .begin (  ) ; !i.atEnd (  ) ; i.advance (  )   )  {  
             listCandidats.add ( i.get (  )  ) ; // A given matrix 
          }  
          
         return listCandidats; 
                   
      }  
  
  
 Symbol HasSetIterator cannot be solved, but import java.util.* is present.


public boolean remove(Object o)
See Also:
E, AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int size()
See Also:
E, AbstractCollection, Set, Collection
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags