2014년 3월 25일 화요일

JAVA Set(자바자료구조, JCF Set) 예제[자바교육잘하는곳/자바교육추천/자바학원추천/JAVA학원교육추천/JAVA교육학원추천/실무자바교육]

JAVA Set(자바자료구조, JCF Set) 예제[자바교육잘하는곳/자바교육추천/자바학원추천/JAVA학원교육추천/JAVA교육학원추천/실무자바교육]

참고하세요~ 자바공부 열심히..


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
value2 : onjsystems
 



댓글 없음:

댓글 쓰기