프로그램

java 의 List , Arraylist 의 차이점.

(주)CKBcorp., 2012. 6. 16. 18:23
반응형

몰라서 찾아보니, 이런 게 나왔다. 


원본은 요기 : http://www.javabeat.net/qna/9-difference-between-list-and-arraylist-/


List is an interface and ArrayList is an implementation of the List interface. The arraylist class has only a few methods in addition to the methods available in the List interface. There is not much difference in this. The only difference is, you are creating a reference of the parent interface in the first one and a reference of the class which implements the List (i.e) the ArrayList class in the second. If u use the first, you will be able to call the methods available in the List interface and you cannot make calls to the new methods available in the ArrayList class. Where as, u are free to use all the methods available in the ArrayList, if u use the second one.

To add some more points to this,

1. I would say the first approach is a better one because, when you are developing java applications, when you are supposed to pass the collection framework objects as arguments to the methods, then it is better to go with


List tempList = new ArrayList();
somemethodcall(tempList);

Why am i saying this because, in future due to performance constraints, if you are changing the implementation to use linkedlist or someother classes which implements List interface, instead of ArrayList, you can change at only one point (i.e) only the instantiation part. Else u ll be supposed to change at all the areas,whereever, u have used the specific class implementation as method arguments.

You cannot check for performance in this. Instead u can check for performances of the implementing classes of List interface in the following link. It explains you about the performance statistics of the collection framework


그러고 보니, java의  implement 를 한글로 뭐라고 하는지 모르겠네? 쨌던...


한줄요약 : ArrayList 는 List 의 구현체( implement )다. 너님들 그냥 써도 됨. 


 


반응형

'프로그램' 카테고리의 다른 글

파일 확장자 종류.  (0) 2012.09.13
stopPropagation() 과 preventDefault() 의 차이.  (4) 2012.08.24
php 에서 & 와 @ 의 뜻.  (0) 2012.05.24
워드프레스  (0) 2012.05.21
php 에서 var 키워드의 사용.  (0) 2012.05.21