ArrayList 예제
- List 계열 특징 : 중복 저장 가능하며 저장 순서 있음
import java.util.ArrayList; public class dailyCode { public static void main(String []args){ ArrayList list = new ArrayList<>(); String[] add = new String[5]; int i = 0;
for(String str : add){ str = "add" + i++; list.add(str); }
for(int j=0; j<list.size(); j++){ System.out.println(list.get(j)); }
list.set(0, "set0"); list.remove(3); list.remove("add4");
System.out.println("----"); for(int j=0; j<list.size(); j++){ System.out.println(list.get(j)); } } } |
'프로그래밍 > JAVA' 카테고리의 다른 글
| arraycopy Example (0) | 2016.11.19 |
|---|---|
| scheduleAtFixedRate vs. scheduleWithFixedDelay (0) | 2016.11.18 |
| Callback using interface (0) | 2016.11.17 |
| Singleton Design Pattern (0) | 2016.11.16 |
| 초기화 블록 (Initialization Block) (0) | 2016.11.15 |
| HashSet 예제 (0) | 2016.11.15 |
| 생성자 예제 (Constructor Example) (0) | 2016.11.13 |