在 Java 中显示 HashMap 的内容
让我们首先创建一个 HashMap 并添加元素 -
HashMap hm = new HashMap();
hm.put("Wallet", new Integer(700));
hm.put("Belt", new Integer(600));要显示内容,只需打印 HashMap 对象 -
System.out.println("Map = "+hm);以下示例显示如何显示 HashMap 的内容 -
示例
import java.util.*;
public class Demo {
public static void main(String args[]) {
// Create hash map
HashMap hm = new HashMap();
hm.put("Wallet", new Integer(700));
hm.put("Belt", new Integer(600));
System.out.println("Map = "+hm);
}
}输出
Map = {Belt=600, Wallet=700}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP