자바 Collections의 이해 (extends, implements)

최성민·2021년 1월 24일
0

자바

Interface, Class의 차이

Interface :

Methode만 선언하여 자식 객체에서 implements후 재정의(Overriding)해서 사용해야함.

Class :

선언, 정의를 모두함. 자식은 메소드 / 변수를 그대로 사용할 수 있음.     
        
        

List, Queue, Set은 Collections의 인터페이스를 구현함.

Collections vs Collection

Collection은 Interface
Collections는 Utility Class

Collection의 기본 Method

여기 Method들은 Static이라 인스턴스를 생성하지 않고 사용할 수 있음.

자주 사용하는 것

void형 method
fill(List<? super T> list, T obj)
reverse(List<?> list)
swap(List list, int i, int j)
sort(List list)
sort(List list, Comparator<? super T> c)

reverseOrder()
reverseOrder(Comparator cmp)

나중에 필요할 수 있는 것

void형 method
rotate(List<?> list, int distance)

int형 method
binarySearch(List<? extends Comparable<? super T>> list, T key)
binarySearch(List<? extends T> list, T key, Comparator<? super T> c)

Collections의 Method

자주쓸 것같은거
add()
contains(Object o)
equals(Object o)
isEmpty()
iterator()
remove(Object o)
size()
toArray() -> Object[]를 return
toArray(T[] a)

T[] a가 저장될 배열, 크기가 더 클 경우엔 재할당됨 
	String b = new String[al.size()];
	b = al.toArray(b);

참고사이트

extneds, implements에 대한 설명

extends, implements 사용 예시

profile
공부합시다

0개의 댓글

관련 채용 정보