集合总结

1.单列集合框架结构

|----Collection接口:单列集合,用来存储一个一个的对象。
–|------List接口:存储有序的,可重复的数据。 -->“动态"数组
----|--------ArrayList、LindedList、Vector(常见实现类)
–|------Set接口:存储无序的、不可重复的数据 -->类似高中讲的"集合”
----|--------HashSet、LinkedHashSet、TreeSet(常见实现类)
|----Map接口:双列集合,用来存储一对(key - value)一对的数据。键值对 -->高中函数: y=f(x);
----|------HashMap、LindedHashMap、TreeMap、Hashtable、Properties(常见实现类)
对应图示:集合图示

2.Collection接口常用方法(15个):

①add(Object obj);
②addAll(Collection coll);
③size();
④isEmpty();
⑤contains(Object obj);
⑥containsAll(Collection coll);
⑦remove(Object obj);
⑧clear();
⑨equals();
⑩removeAll(Collection coll);差集
⑪retainsAll(Collection coll);交集
⑫toArray();
⑬hashCode();
⑭iterator();
⑮ T[] toArray(T[] a);

3.Collection集合与数组间的转换。

集合—>数组 toArray()
Object[] array = coll.toArray();
for (int i = 0; i < array.length; i++) {
System.out.println(array[i]);
}

数组—>集合 Arrays.asList()
List asList = Arrays.asList(new String[] {“AA”,“BB”,“CC”});
System.out.println(asList);
List arr1 = Arrays.asList(new Integer[] {123,456});

4.使用Collection集合存储对象,要求对象所属的类满足。

向Collection接口的实现类的对象中添加数据obj时,要求所在类要重写equals();方法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值