Showing posts with label hashtable iterateion. Show all posts
Showing posts with label hashtable iterateion. Show all posts

Wednesday, March 28, 2012

Get all value from hashtable in java(iterate in hash table in java)

//Print all values from hash table

public static void PrintHashTableValue( Hashtable hashTableVar )
    {
        Collection valueCollection = hashTableVar.values();
        Object hashTablevalueObject[] = valueCollection.toArray();
        for ( Object hashValueObject : hashTablevalueObject )
       {
            System.out.println( hashValueObject );
        }
   
   }

//Print key and value from hashtable

public static void PrintHashTableKeyPair(Hashtable hashTableVariable)
     {
        Enumeration hashTableKeys = hashTableVariable.hashTableKeys();
        while (hashTableKeys.hasMoreElements())
       {
            Object hashTableKey = hashTableKeys.nextElement();
            System.out.println(" Key :" + hashTableKey + " Value: " + hashTableVariable.get(hashTableKey));
       }
     }





Simply You can use it like this :

Set s = hastable.entrySet();
Iterator it = s.iterator();
  while (it.hasNext())
{ 
   System.out.println(it.next());
}
































Featured Posts

Kali Linux Remote Desktop: Access GNOME from Windows Using Native RDP

  Kali Linux + GNOME 50 + GNOME Remote Desktop + Windows Remote Desktop (MSTSC) Getting a full GNOME desktop remotely on Kali Linux can be ...