9:41 am - Wednesday December 19, 2018

Java Iterate through values of Java Hashtable

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

*/
import java.util.Hashtable;
import java.util.Enumeration;
class IterateValuesOfHashtable {
public static void main(String[] args) {
//creating Hashtable Object
Hashtable ht = new Hashtable();
ht.put("1","One");
ht.put("2","Two");
ht.put("3","Three");
//using enumeration the values arecalled
Enumeration e = ht.elements();
//to iterate the values from a list use hasMoreElements to get next values concurently
while(e.hasMoreElements())
System.out.println(e.nextElement());
}
}

Output:

D:\CandidJava\Util\HashTable>javac IterateValuesOfHashtable.java

Note: IterateValuesOfHashtable.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\HashTable>java IterateValuesOfHashtable

Three

Two

One

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply