在 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