연결리스트와 set의 차이는
Set의 Class는 위와 같이 구성이 된다. 우리는 HashSet과 TreeSet을 주로 사용하게 될 계획이다.
Constructor은 위의 4가지가 존재한다.
![<https://images.velog.io/images/tonyhan18/post/71158347-b6fa-4d9b-86fb-d8d56d92b47b/image.png>](<https://images.velog.io/images/tonyhan18/post/71158347-b6fa-4d9b-86fb-d8d56d92b47b/image.png>)
이 외의 함수로는 위와 같이 존재한다.
![<https://images.velog.io/images/tonyhan18/post/8d9cdb1b-22df-422e-8bb1-ebf0708912fc/image.png>](<https://images.velog.io/images/tonyhan18/post/8d9cdb1b-22df-422e-8bb1-ebf0708912fc/image.png>)
class Lecture {
public static void main(String[] args) {
String[] strArr = {"1", "1", "2", "2", "3", "3", "4", "4", "4"};
Set<String> set = new HashSet<>();
// set에 element가 계속 추가 된다.
for(int i=0; i<strArr.length; i++) {
set.add(strArr[i]);
}
System.out.println(set);
}
}
중복을 허용하지 않기 때문에 다음과 같은 출력결과가 나올 것이 예상된다.
// ArrayList로 했을때의 결과