Get the set of values in Java IdentityHashMap


To get the set of values in IdentityHashMap, use the values() method.

First, set the IdentityHashMap

Map<String, Integer> m = new IdentityHashMap<String, Integer>();
m.put("1", 100);
m.put("2", 200);
m.put("3", 300);
m.put("4", 150);
m.put("5", 110);
m.put("6", 50);
m.put("7", 90);
m.put("8", 250);
m.put("9", 350);
m.put("10", 450);

Now, retrieve the set of values

m.values()

The following is an example to get the set of values in IdentityHashMap using values() method

Example

 Live Demo

import java.util.*;
public class Demo {
   public static void main(String[] args) {
      Map<String, Integer> m = newIdentityHashMap<String, Integer>();
      m.put("1", 100);
      m.put("2", 200);
      m.put("3", 300);
      m.put("4", 150);
      m.put("5", 110);
      m.put("6", 50);
      m.put("7", 90);
      m.put("8", 250);
      m.put("9", 350);
      m.put("10", 450);
      System.out.println("IdentityHashMap elements
"+ m); System.out.println("
Set of Values = " + m.values()); } }

The following is the output

IdentityHashMap elements
{2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300}
Set of Values = [200, 150, 350, 90, 450, 50, 110, 250, 100, 300]

Updated on: 30-Jul-2019

68 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements