Java Set

175.197.192.184 (토론)님의 2021년 10월 12일 (화) 21:16 판 (새 문서: ==개요== ;각 값이 겹치지 않고 고유한 값을 가진 collection 이다 ;합집합, 차집합, 교집합 연산이 가능하다 * hash set 예제 <syntaxhighlight lang='java...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요

각 값이 겹치지 않고 고유한 값을 가진 collection 이다
합집합, 차집합, 교집합 연산이 가능하다
  • hash set 예제
import java.util.HashSet;

public class Main {
  public static void main(String[] args) {

    HashSet<Integer> numbers = new HashSet<Integer>();

    numbers.add(4);
    numbers.add(7);
    numbers.add(8);

    for(int i = 1; i <= 10; i++) {
      if(numbers.contains(i)) {
        System.out.println(i + " was found in the set.");
      } else {
        System.out.println(i + " was not found in the set.");
      }
    }
  }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}