Home Tutorial Java Core HashMap Example of values() method of HashMap.


Share on Google+Share on Google+
Example of values() method of HashMap.
Posted on: April 6, 2011 at 12:00 AM
In the tutorial you will learn about the values() method of HashMap class.

Example of values() method of HashMap.

The values() is the method of java HashMap. It returns a collection object of HashMap values. 



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

Output :

Values : AAA

Values : BBB

Values : CCC

Values : DDD

Values : EEE


Related Tags for Example of values() method of HashMap.:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 6, 2011

Recommend the tutorial

Advertisements Advertisements