Tuesday, 5 February 2019

3.How to print all map values in java.


Description:
Write a sample code to print all map values.


Code:
?

1
2
3
4
5
6
7
8
9
10

import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class PrintMapvalue { public static void main(String[] args) { HashMap<String, String> hmap = new HashMap<String, String>(); hmap.put("1000", "God"); hmap.put("2000", "Bless"); hmap.put("3000", "Govind"); Collection c = hmap.values(); Iterator itr = c.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } } }

Output:
God
Bless
Govind

No comments:

Post a Comment