LinkedList:
集合数据存储的结构是链表结构, 方便元素添加, 删除
LinkedList 是 List 的子类
- LinkedList<String> lis=new LinkedList<String>();
- list.addFirst("aa");
- list.addLast("dd");
- list.getFirst()
- list.removeFirst();
- boolean flag=list.isEmpty();
- Vector:
类似于迭代器, hasMoreElements()=hasNext()
nextElement()=next
HashSet 集合:
不能存相同元素, 不能保证的迭代顺序与元素存储顺序相同.
HashSet 中存放自定义类型元素时, 需要重写对象的 hashCode 和 equals 方法, 才能保证集合中的对象唯一
- public int hashCode() {
- return name.hashCode()+age;
- }
- public boolean equals(Object obj){
- if(obj instanceof Person){
- Person p=(Person)obj;
- return p.name.equals(this.name)&&p.age==this.age;
- }
- if(obj==null){
- return false;
- }
- if(obj==this){
- return true;
- }
- return false;
- }
来源: http://www.bubuko.com/infodetail-3216616.html