-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8. Collections #14
Comments
|
|
자바에는 자료구조에 관련된 Collections 라는 패키지가 있고 크게 LIst, Set, Map 으로 나뉘는데 이는 각각 python의 list, set, dict와 유사하다. 이 중 List와 Set은 Collections 라는 인터페이스를 상속 받는다 c++에서 STL을 이용하여 자료구조를 표현할 때 템플릿 문법을 사용했던 것처럼 자바에서도 제네릭 문법을 사용하여 해당 자료구조들을 구현할 수 있다 List는 크게 Vector(stack), ArrayList, LinkedList 로 나뉘는데 Vector는 삽입은 느리지만 탐색이 빠르다, 그리고 이 vector를 개선한 것이 ArrayLIst로 자바에서 list를 구현할 때 아주 많이 사용된다. 마지막으로 LinkedList는 ArrayList와는 반대로 삽입은 빠르지만 탐색은 좀 느리다. LIst에서 sort 메서드를 사용할 때는 자바스크립트의 callback함수 처럼 Comparator 객체를 List.sort() 안에서 구현해줘야 한다 내부의 compare 메서드를 오버라이드 하며 상황에 맞게 -1, 0, 1을 return하게 구현하면 된다. Set은 일반적인 Set인 HashSet이 있고 저장순서를 보장하는 LinkedHashSet이 존재한다. 그리고 저장순서는 보장되지 않지만 정렬상태가 유지되는 TreeSet도 존재한다 Map이란 key, value 한 쌍으로 data를 저장하는데 일반적인 HashMap이 있고 삽입순서를 보장해주는 LinkedHashMap, 그리고 트리구조를 이용하여 키를 정렬할 수 있는 TreeMap 이 존재한다. Hash로 시작하는 collections 들은 hash 구조 특성상 자료의 삽입 순서 등은 보장하지 않지만 탐색이 빠르다. |
|
Collections List 제너릭 문법 Set Map |
|
|
|
강의 자료
아래 이슈에 답글로 5줄 요약을 남겨 주세요.
The text was updated successfully, but these errors were encountered: