LinkedList vector集合,Set接口

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;
    }
原文地址:https://www.cnblogs.com/god3064371/p/11601813.html