Vector와 ArrayList

old/JAVA 2010. 5. 24. 17:32
Vector를 개선한 것이 ArrayList.
Vector는 기존 코드를 위해 남겨둔 것이므로 가능한 ArrayList를 사용.

공통점: List 인터페이스 구현, 저장순서 유지/중복 허용, 배열을 사용, 용량 부족시 늘어나긴 하지만 시간 오래걸림
차이점: Vector는 멀티쓰레드에 대하여 동기화가 되어있다.
          
ex)

class ArrayListEx2 {
 public static void  main(String[] args) {
   final int LIMIT = 10;
   String source = "0123456789abcdefghijklmnop";
   int length = source.length();
 
   List list = new ArrayList(length/LIMIT+10);

   for(int i=0; i<length; i+=LIMIT) {
     if(i+LIMIT<length)
           list.add(source.substring(i, i+LIMIT));
     else
           list.add(source.substring(i));
    }

    for(int i=0; i<list.size(); i++) {
        System.out.println(list.get(i));
    }
 }
}

'old > JAVA' 카테고리의 다른 글

Stack과 Queue  (0) 2010.05.24
LinkedList  (0) 2010.05.24
Synchronization (ArrayList, HashMap)  (0) 2010.05.24
Collection Framework  (0) 2010.05.24
garbage collection 이란?  (0) 2010.05.10
Posted by jazzlife
,