Collections、

1、Collections

public class Collections extends Object

Collection是接口,Collections是类
只有静态方法--直接用类名调用--针对集合操做的工具类
image.png
操做:
image.png数组

2、案例一

image.png
image.png
排序操做:
不能用sort(array),须要在Student类中重写CompareTo()方法
Collection 中有内部类添加比较器的方法工具

static <T> void sort(List<T> list,Comarator<? super T> c)

image.png

3、案例二

image.png
image.png
录入牌:
定义String数组就行,不用ArrayList<>就复杂了
两个加强for
image.png
洗牌:spa

Collections.sort(array);

发牌:
这里必须把底牌的存入写到第一个if里,写后面就不执行了
image.png
看牌:
image.pngcode

案例升级

image.png
image.png
image.png
HashMAp:
键是编号Integer,值是牌String,而不是ArrayList<>
image.png
录入牌:
嵌套加强for 外层是number,内层color,才能获得四种花色同时从小到大的顺序
不须要new ArrayLis存poker,直接存入HashMap里
image.png排序

洗牌:
洗编号
image.png索引

发牌:
TreeSet自动天然排序
image.png
看牌:
在main方法外自定义方法
须要有索引TreeSet 和 HashMap
image.png
调用方法:
image.png接口

相关文章
相关标签/搜索