데이터의 순서가 없다.
중복 데이터가 없다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import java.util.HashSet;
public class MyClass{
public static void main(String args[]){
// 키와 값
HashSet<String> hashSet = new HashSet<String>();
hashSet.add("str0");
hashSet.add("str1");
hashSet.add("str2");
hashSet.add("str1"); // 중복됨으로 데이터를 허락하지 않음
System.out.println(hashSet.toString());
hashSet.remove("str0"); // str0 삭제됨
System.out.println(hashSet.toString());
int count = hashSet.size();
System.out.println("사이즈 = " + count);
}
}
| cs |
result
댓글
댓글 쓰기