본문 바로가기

JAVA/되새김질

ArrayList

import 필요 -  import java.util.ArrayList;

 

객체생성  -  ArrayList<Integer> arrayList = new ArrayList<>();

                  ArrayList 크기는 동적으로 변경되기 때문에 크기설정이 필요없음

 

값 추가  -  .add("##"); ##이 마지막 배열에 추가됨.

             -  .add(1, "@@"); 이 index[1]에 끼어들어감.

 

값 제거  -  .remove(0); index[0]이 지워지면서 자동으로 1번이 0번째 index가 됨.

 

값 찾기  -  .get(i); index[i] 의 값을 볼 수 있다.

 

값 수정  -  .set(1, 77779); index[0] 의 값이 77779로 바뀜.

           cf) .add(1, "@@"); 이 index[1]에 끼어들어감.

 

존재확인 -  boolean isEmpty = mArrayList.isEmpty();