HashSet<데이터타입> 변수명 = new HashSet<데이터타입>();
HashSet<Integer> : Integer형의 HashMap 데이터
HashSet<String> : String형의 HashMap 데이터
HashSet의 특정 값이 있나 확인 시 contains(value) 메소드를 사용
값이 존재한다면 true, 값이 없다면 false를 return
HashSet<Integer> A = new HashSet<>();
A.contains(b)
코드
import java.util.*;
public class No_1269 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int count=0;
int acnt=sc.nextInt();
int bcnt=sc.nextInt();
HashSet<Integer> A = new HashSet<>();
HashSet<Integer> B = new HashSet<>();
for(int i=0;i<acnt;i++) {
A.add(sc.nextInt());
}
for(int i=0;i<bcnt;i++) {
B.add(sc.nextInt());
}
for(Integer b:B) {
if(!A.contains(b))
count++;
}
for(Integer a:A) {
if(!B.contains(a))
count++;
}
System.out.println(count);
}
}
결과