3:11 pm - Tuesday November 25, 8397

EnumMap returns a Collection view of the values contained in this map using Values() method

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

BACK

This Program used EnumMap returns a Collection view of the contained in this map using Values() method

Example Program


package com.example;
import java.util.*;

public class EnumMapDemo { // create an enum
	public enum Numbers {
		ONE, TWO, THREE, FOUR, FIVE
	};

	public static void main(String[] args) {
		EnumMap<Numbers, String> map = new EnumMap<Numbers, String>(
				Numbers.class);
		// assosiate values in map
		map.put(Numbers.ONE, "1");
		map.put(Numbers.TWO, "2");
		map.put(Numbers.THREE, "3");
		map.put(Numbers.FOUR, "4");
		// print the map
		System.out.println("Map: " + map);
		// create a new collection and create the view
		Collection<String> values = map.values();
		// print the collection view
		System.out.println("Collection:" + values);
	}
}


Output:

Map: {ONE=1, TWO=2, THREE=3, FOUR=4}
Collection:[1, 2, 3, 4]

Description

The java.util.EnumMap.values() method returns a Collection view of the values contained in this map.

Declaration

Following is the declaration for java.util.EnumMap.values() method

public Collection<V> values()

Parameters

  • NA

Return Value

This method returns a collection view of the values contained in this map

Exception

  • NA

BACK

Filed in: Java Examples

Comments are closed.