본문 바로가기

language/자바

자바 ArrayList , List

처음 List를 쓸때  언제는 앞에서 List쓸때가 있고 언제는 ArrayList 쓸때가 있길래 뭐지 했다

List<String> list = new ArrayList<>();

ArrayList<String> list = new ArrayList<>();

알고보니 둘다 잘되니까 똑같다 생각했는데

 

엄밀히 말하자면

 

List = 인터페이스, ArrayList=클래스

 

ArrayList <> 는 ArrayList<>();

밖에 될수없지만

 

List<>는 

List<> list = new ArrayList<>();

List<> list = new LinkedList<>();

List<> list = new Vector<>();

이렇게 될수있다.

 

 

 

즉, List가 유연성이 더 크다고 보면된다 

 

관계들은 다음과 같다 

 이렇게 표현할수 있다.

Set<> set = new HashSet();
Set<> set = new TreeSet();

Map<> map = new HashMap();
Map<> map = new Hashtable();
Map<> map = new TreeMap();

 

 

더자세한 내용은 

컬렉션 프레임워크를 공부하자