-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2.java
More file actions
42 lines (27 loc) · 859 Bytes
/
test2.java
File metadata and controls
42 lines (27 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Iterator;
import java.util.LinkedList;
public class test2 {
public static void main(String[] args) {
LinkedList list = new LinkedList<String>();
list.add("cat");
list.add("cats");
list.add("dog");
list.add("dogs");
System.out.println(list);
removedEvenLength(list);
System.out.println("Linked list with iterator after...");
System.out.println(list);
}
// remove all string of even length from a list
// we use array list // linked
//not efficient call get and remove many times
public static void removedEvenLength(LinkedList<String> list){ //ARRAY AND LINKED
Iterator< String> i = list.iterator();// call iterator
while ( i.hasNext()){
String element = i.next();
if (element.length()%2 == 0){// even
i.remove();
}
}
}
}