单例集合的使用

集合的结构框架

在这里插入图片描述

List集合

方法:这些方法时来自jdk1.8进行解读的,有一些其中有两个方法不太知道怎么使用。

int size();
boolean isEmpty();
boolean contains(Object o);
Iterator<E> iterator();
Object[] toArray();
boolean remove(Object o);
boolean containAll(Collection c);
boolean addAll(Collection c);
boolean addAll(int index,Collection c) 从开始到index
boolean removeAll(Collection c)
boolean retainAll(Collection c) 在两个集合不相同的情况下 查询两个集合的交集
default void replaceAll(UnaryOperator<E> operator) 这个方法时1.8后的,不太知道怎么使用
default void sort(Comparator c);
void clear();
boolean equals(Object o);
int hashCode();
int indexOf(Object o);
int lastIndexOf(Object o);
ListIterator listIterator();可以进行元素操作的迭代器
ListIterator listIterator(int index);从index进行迭代
subList(int fromIndex,int toIndex);从fromIndex截取到toIndex
default Spliterator<E> spliterator();这个方法不知道怎么使用

之前一直都不太知道jdk1.8的特性,这次看到有接口中存在方法体和一些静态方法。写方法体的方法必须要用default来修饰。

1.ArrayList集合

1.默认大小为——10
2.使用static final Object[] 数据来装数据
3.使用一个 size 来记录集合的大小
	特点:有序可重复
		  以数组的形式进行存储,查询快,增删慢

1、初始化

	public ArrayList(int initialCapacity)
	public ArrayList()
	public ArrayList(Collection c)

2、ArrayList中一些常用的方法

boolean add(E e)
void add(int index, E e);
public E set(int index, E e);
public E get(int index);
public E remove(int index);
public boolean remove(Object o);
public void clean();
public boolean addAll(Collection c);
public boolean addAll(int index,Collection c)
public boolean removeAll(Collection c);
public ListIterator listIterator(int index);
public ListIterator listIterator();
public Iterator iterator();

Set集合

Set集合感觉和list集合中的方法差不多,
	特点:无序、不可重复、允许有null

主要方法:

HashSet集合

它使用HashMap 中的key来存储,保证了它的唯一性。他是按照hash算法排序
	没有get()方法 没有get()方法 没有get()方法!!!

方法:

	boolean add(object o);
	void clear();
	boolean contains(object o);
	Iterator iterator();
	boolean remove(object);
	int size();

迭代器遍历

		Set set = new HashSet();
		Iterator it = set.iterator();
		while(it.hasNext()){
			system.out.println(it.next());
		}

for循环遍历

Set set = new HashSet();
	for(Object obj : set){
		system.out.println(obj);
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值