Skip to content

Commit 63cf589

Browse files
committed
新增:ListIterator 的使用
1 parent 5a6796e commit 63cf589

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.javacore.collection.list; /*
2+
* Copyright [2015] [Jeff Lee]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
import java.util.ListIterator;
20+
21+
/**
22+
* @author BYSocket
23+
* @since 2016-01-06 20:11:00
24+
* 打印list 全部元素,并找到其中元素aaa删除。要求:所有元素都遍历完
25+
* ListIterator 的使用
26+
*/
27+
public class ListT0 {
28+
public static void main(String[] args) {
29+
List<String> list =new ArrayList<>();
30+
list.add("1");
31+
list.add("2");
32+
list.add("3");
33+
list.add("4");
34+
list.add("aaa");
35+
list.add("6");
36+
list.add("7");
37+
38+
ListIterator listIterator = list.listIterator();
39+
while (listIterator.hasNext()) {
40+
Object o = listIterator.next();
41+
System.out.println(o);
42+
if (o.equals("aaa")) {
43+
listIterator.remove();
44+
}
45+
}
46+
}
47+
48+
}

0 commit comments

Comments
 (0)