-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestIterator.java
More file actions
36 lines (32 loc) · 799 Bytes
/
Copy pathTestIterator.java
File metadata and controls
36 lines (32 loc) · 799 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
package com.example;
import java.util.*;
public class TestIterator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Collection books = new HashSet();
books.add("J2EE企业应用实战");
books.add("Struts2权威指南");
books.add("Thinking in Java");
//foreach读取
for(Object obj:books)
{
String book =obj.toString();
System.out.println(book);
}
Iterator it =books.iterator();
while(it.hasNext())
{
String book =it.next().toString();
System.out.println(book);
if (book.equals("Struts2权威指南"))
{
it.remove();
}
book="测试";
}
System.out.println(books);
}
}