package doudou; import java.util.HashMap; import com.alibaba.fastjson.JSONObject; public class test_hashMap { public static void main(String[] args) { HashMap<String,Integer>hm=new HashMap<>(); System.out.println("------------java.util.HashMap----------------"); //新增 hm.put("张三", 12); hm.put("王五", 12); hm.put("clover", 22); hm.put("dou",333); hm.put("刘一", 1); System.out.println("hm:"+hm); //判断 if (hm.equals("clover")){ System.out.println("存在clover"); } //移除 hm.remove("clover"); System.out.println("clover已经被移除:"+hm); //查看大小 int a=hm.size(); System.out.println("字典的长度为:"+a); //变成string String b=hm.toString(); System.out.println("toString方法:"+b); //替换 hm.replace("刘一", 999); System.out.println("replace方法:"+hm); //查询 Integer c=hm.get("刘一"); System.out.println("key为刘一的新对应的value是:"+c); //判断字典是否为空 if(hm.isEmpty()){ System.out.println("字典为空"); } else{ System.out.println("字典不为空"); } //清空字典 hm.clear(); System.out.println("清空后的字典为:"+hm); System.out.println("------------com.alibaba.fastjson.JSONObject------------"); JSONObject result = new JSONObject(); result.put("json", 111); result.put("json", 111); result.put("json1", 111); result.put("json", 1112); System.out.println("fastjson练习:"+result); System.out.println(result.getClass()); } }