2:24 am - Tuesday March 28, 2017

Change the HashMap to Collection (value) Collection 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

 BACK

                         This method is used to return a collection view of the values contained in the hash map. Retrives all Values from the hashMap and add them in a Collection Object.

Example program


import java.util.HashMap;

public class Hash3 {

	public static void main(String[] args)

	{

		HashMap<String, Integer> h1 = new HashMap<String, Integer>();

		System.out.println("collections");

		System.out.println("List");

		h1.put("Linked list", 0);

		h1.put("Array List", 1);

		h1.put("Vector", 2);

		h1.put("Stack", 3);

		System.out.println(h1);

		System.out.println("collection view of values:" + h1.values());

	}

}

Output

   Collections

   List

   {Stack=3, Array List=1, Linked list=0, Vector=2}

   collection view of values:[3, 1, 0, 2]

BACK

Filed in: Java Examples

Comments are closed.