public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("zhangsan");
list.add("lisi");
list.add("wangwu");
list.add("zhaoliu");
for (int i = 0; i < list.size(); i++) {
String str = list.get(i);
System.out.print(str + " ");
}
System.out.println();
for (String str : list) {
System.out.print(str + " ");
}
System.out.println();
Iterator<String> it = list.iterator();
while (it.hasNext()) {
String str = it.next();
System.out.print(str + " ");
}
Set<String> set = new HashSet<String>();
set.add("zhangsan");
set.add("lisi");
set.add("wangwu");
set.add("zhaoliu");
System.out.println();
for (String str : set) {
System.out.print(str + " ");
}
}
网友评论