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());
}
































No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...