Java中HashMap使用范例代码
import java.util.HashMap; public class prices { public static void main(String[] args) { HashMap<String,Integer> prices = new HashMap<String,Integer>(); prices.put("walmart", 88); prices.put("target", 100); prices.put("kmart", 77); prices.put("lowes", 90); System.out.println("walmart's price: " + prices.get("walmart")); System.out.println("Number of prices: " + prices.size()); if (prices.containsKey("target")) { prices.remove("target"); System.out.println("Record successfully removed."); } System.out.println("number of prices: " + prices.size()); } }