9:47 pm - Monday October 15, 2018

HashMap Example program for values()

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
/**
Author :candidjava.com
Description: It returns a collection object of HashMap values.
*/
import java.util.*;
public class HashMapValues
 {
public static void main(String arg[])
{
HashMap<Integer, String> osHashMap = new HashMap<Integer, String>(); // Create object  of hashmap
osHashMap.put(new Integer(1), "ABC");
osHashMap.put(new Integer(2), "DEF");
osHashMap.put(new Integer(3), "GHI");
Collection<String> collection = osHashMap.values();
Iterator obIter = collection.iterator();
while (obIter.hasNext())
{
String str = (String) obIter.next();
System.out.println("Values : " + str);
}
}
}
 

Output:
Values : ABC
Values : DEF
Values : GHI

BACK

Filed in: Z-A All Java Codes

Comments are closed.