ArrayList class

Java/Collection 2012.01.19 15:57 |

ArrayList class :

- uses a dynamic array for storing the elements. It extends AbstractMap class and implements List interface.
- can contain duplicate elements.
- maintains insertion order.
- not synchronized.
- random access because array works at the index basis.
- manipulation slow because a lot of shifting needs to be occured.

2012:01:19 15:37:09



Example of ArrayList :


import java.util.*;

public class Simple {
public static void main(String args[]) {
ArrayList al = new ArrayList();
al.add("A");
al.add("B");
al.add("C");
al.add("D");

Iterator itr = al.iterator();
while(itr.hasNext()) {
System.out.println(itr.next());
}

/* Enhanced for 사용
for(Object s: al) {
    System.out.println(s);
}
*/
}
}


Output :

A
B
C
D

신고

'Java > Collection' 카테고리의 다른 글

Mergesort  (0) 2012.01.27
Quicksort  (0) 2012.01.27
LinkedList class  (0) 2012.01.19
ArrayList class  (0) 2012.01.19
Posted by jeonguk