LinkedList vector集合,Set接口

半世苍凉 提交于 2019-11-30 15:49:47

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;
    }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!