21
22
String oldStr=it.next();
23
24
if(newStr.equals(oldStr)){
25
26
isExists=true;
27
28
}
29
30
}
List(列表): List 的特征是其元素以线性方式存储,集合中可以存放重复对象。
List 接口主要实现类包括:
6
ArrayList() : 代表长度可以改变得数组。可以对元素进行随机的访问,向 ArrayList()中
插入与删除元素的速度慢。
7
LinkedList(): 在实现中采用链表数据结构。插入和删除速度快,访问速度慢。
对于
List 的随机访问来说,就是只随机来检索位于特定位置的元素。 List 的 get(int
index) 方法放回集合中由参数 index 指定的索引位置的对象,下标从“0” 开始。最基本的两
种检索集合中的所有对象的方法:
1: for 循环和 get()方法:
31
for(int i=0; i<list.size();i++){
32
33
System.out.println(list.get(i));
34
35
}
2: 使用 迭代器(Iterator):
36
Iterator it=list.iterator();
37
38
while(it.hashNext){
39