Notice
Recent Posts
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- jquery
- 알고리즘
- 셋업
- 깃허브 간단요약
- Eclipse
- 폼태그
- Oracle
- 설치
- 버튼
- 이클립스
- springboot
- jsp 내부객체
- 오라클
- 면접
- 필터체인
- java
- html
- EL태그
- jsp
- MySQL
- Spring
- 스프링
- 자바스크립트
- 마이바티스
- 설정
- SESSION
- 깃허브
- jstl
- 자바
- 제이쿼리
Archives
- Today
- Total
은은하게 코드 뿌시기
컬렉션프레임웍(Collections Framework) - HashSet 본문
728x90
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package data_structure;
import java.util.*;
class code1_Hashset {
public static void main(String[] args) {
System.out.println("Hashset test");
//해시는 중복된 값을 저장하지 않는다.
int[] arr1= {1,2,30,5,4,7,8,10,2,9,10,11,21,20,18};
Object[] arr;
Set set = new HashSet();
Set set2 = new LinkedHashSet();
//비어있는지확인
System.out.println(set.isEmpty());
for (int i=0; i<arr1.length; i++) {
set2.add(arr1[i]);
if (!set.add(arr1[i])){
System.out.printf("중복된데이터 (%d) : %d %n", i, arr1[i]);
}
}
//저장된 데이터 삭제
set2.remove(11);
//HashSet은 저장순서를 유지 하지않는다.오름차순으로 정렬된다.
System.out.println("count " + set.size());
System.out.println(set);
//LinkedHashSet은 저장순서를 유지 한다.
System.out.println(set2);
//포함여부
System.out.println(set.contains(7));
//배열로 변환
arr = set.toArray();
System.out.println(Arrays.toString(arr));
//set엔 get이없다 이터레이터로 받아 값을 찾을 수있다.
Iterator it = set.iterator();
while(it.hasNext()) {
int temp = (int)it.next();
System.out.println(temp);
if (temp==18) {
System.out.println("찾았다! " + temp);
break;
}
}
}
}
|
cs |
Hashset test true 중복된데이터 (8) : 2 중복된데이터 (10) : 10 count 13 [1, 2, 4, 5, 7, 8, 9, 10, 11, 18, 20, 21, 30] [1, 2, 30, 5, 4, 7, 8, 10, 9, 21, 20, 18] true [1, 2, 4, 5, 7, 8, 9, 10, 11, 18, 20, 21, 30] 1 2 4 5 7 8 9 10 11 18 찾았다! 18 |
728x90
'자바 > Collections Framework' 카테고리의 다른 글
컬렉션프레임웍(Collections Framework) - 큐(Queue) (0) | 2022.10.02 |
---|---|
컬렉션프레임웍(Collections Framework) - 스택(stack) (0) | 2022.10.02 |
컬렉션프레임웍(Collections Framework) - ArrayList (0) | 2022.10.02 |
컬렉션프레임웍(Collections Framework) - Arrays 클래스 (0) | 2022.10.01 |
컬렉션 프레임웍(collections framework) - list,set,map (0) | 2022.08.09 |
Comments