package onjjava;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class SetIterTest1 {
public static void main(String[] args) {
HashSet<String> list = new HashSet<String>();
list.add("lee");
list.clear();
list.add("onj");
list.add("oraclejava");
list.add("onjsystems");
list.add("onj");
list.add("chung");
System.out.println(list.size());// size()
System.out.println(list.contains("onjsystems"));
list.remove("onj");
System.out.println(list.size());
print2(list);
print2(list.toArray());
}
public static void print(Set set) {
Iterator iter = set.iterator();
while (iter.hasNext()) {
String str = (String) iter.next();
System.out.println(str);
}
}//
public static void print2(Set<String> set) {
for (String str : set) {
System.out.println("value : " + str);
}
}//
public static void print(Object[] obj) {
int count = obj.length;
for (int i = 0; i < count; i++) {
System.out.println(obj[i]);
}
}//
public static void print2(Object[] obj) {
for(Object o: obj) {
System.out.println("value2 : " + (String)o);
}
}//
}
[결과]
4
true
3
value : oraclejava
value : chung
value : onjsystems
value2 : oraclejava
value2 : chung
댓글 없음:
댓글 쓰기