ArrayList(自动扩展的数组)
方法:
set修改,add,remove,get,indexOf,contains
LinkedList(实现了deque(双向列表)和queue(队列)
双向列表的方法:
getFirst(),getLast(),removeFirst(),removeLast()
队列方法:
poll(),offer()进队列,peek()拿出来看看
HashSet
方法
add(),remove()
HashMap
声明:
HashMap<String,String> dictionary = new HashMap<>();
方法
put(key,value)
remove(key)
申明
List<Hero> genericheros = new ArrayList<Hero>();
或者
List<Hero> genericheros = new ArrayList<>();
这里的Hero就是所说的泛型
申明时不指定泛型的容器可以放任何元素
collection(接口)
Collections(集合的工具类)
Collections.reverse()
Collections.sort()
Collections.rotate() 滚动
遍历
申请迭代器
Iterator<Hero> it= heros.iterator();
while(it.hasNext()){
Hero h = it.next();
System.out.println(h);
}
比较器
方法1.自定义sort函数的Comparator参数
Comparator<Hero> c = new Comparator<Hero>() {
@Override
public int compare(Hero h1, Hero h2) {
}
};
Collections.sort(heros,c);
方法2.实现Comparable接口
public class Hero implements Comparable<Hero>{
@Override
public int compareTo(Hero anotherHero) {
}
}