HashMap 是Java中常用的存储键值对的容器,它集合了
数组(查询快,删除和插入慢)和
链表(查询慢,删除和插入块)两者的优势,可以快速查询和插入,删除. 内部可以
存储常规类型,也可以存储复杂对象.
Test HashMap={1=com.example.testsix.myClass$Person@75b84c92,
2=com.example.testsix.myClass$Person@6bc7c054,
3=com.example.testsix.myClass$Person@232204a1, 4=com.example.testsix.myClass$Person@4aa298b7}
Process finished with exit code 0
2. 原理:
后面补充.
这里先简单介绍下它的使用:
1. Demo:
public class myClass { public static class Person{ public String name; public Person(String str){ name = str; } } public static void main(String[] args){ Map<String, Person> temp = new HashMap<String, Person>(); temp.put("1", new Person("甲")); temp.put("2", new Person("乙")); temp.put("3", new Person("丙")); temp.put("4", new Person("丁")); System.out.println("Test HashMap="+temp.toString()); } }输出:
Test HashMap={1=com.example.testsix.myClass$Person@75b84c92,
2=com.example.testsix.myClass$Person@6bc7c054,
3=com.example.testsix.myClass$Person@232204a1, 4=com.example.testsix.myClass$Person@4aa298b7}
Process finished with exit code 0
2. 原理:
后面补充.