Android
[Android] ArrayList
an-hayyy
2021. 2. 25. 11:03
ArrayList는 크기를 조정할 수 있는 배열
선언 :
ArrayList li = new ArrayList<>();
ArrayList 요소삽입 :
li.add(5) //int
li.add('c') //char
ArrayList 출력 :
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
ArrayList 내의 객체 알아내기 :
Integer obj = (Integer).get(2); //벡터의 1번째 요소를 Integer 타입으로 캐스팅
int i = obj.intValue(); // obj에 있는 정수를 알아냄
ArrayList 의 요소의 개수 :
int n = li.size();
ArrayList 에서 모든 요소 삭제하기 :
li.clear();