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());
}
}
更多信息请查看IT技术专栏