In the tutorial you will learn about the values() method of HashMap class.
In the tutorial you will learn about the values() method of HashMap class.The values() is the method of java HashMap. It returns a collection object of HashMap values.
Code:
HashMapValues.java
package net.roseindia.java; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; public class HashMapValues { public static void main(String[] arr) { /* Create object of HashMap */ HashMap<Integer, String> obHashMap = new HashMap<Integer, String>(); /* Strore value in HashMap */ obHashMap.put(new Integer(1), "AAA"); obHashMap.put(new Integer(2), "BBB"); obHashMap.put(new Integer(3), "CCC"); obHashMap.put(new Integer(4), "DDD"); obHashMap.put(new Integer(5), "EEE"); /* Create a set of keys of hashmap */ Collection<String> collection = obHashMap.values(); Iterator obIter = collection.iterator(); while (obIter.hasNext()) { String str = (String) obIter.next(); System.out.println("Values : " + str); } } } |
Values : AAA Values : BBB Values : CCC Values : DDD Values : EEE |