본문 바로가기

프로그래밍/Java

19.12.19) Java - Calendar 프로젝트

ArrayList

자바에서 제공하는 기본 배열과는 차이가 있다. 크기를 지정할 필요가 없고, add() 통해서 추가하면 동적으로 늘어난다.

선언 방법

ArrayList<Integer> arrayList = new ArrayList<>();
arrayList.add(1); // push 기능
arrayList.add(2);
arrayList.add(1, 10); // 지정 인덱스에 추가 가능. 한 칸씩 밀린다. 
for (int i : arrayList) {
    System.out.println(i) // 1, 10, 2
}

HashMap

Hash라는 이름이 들어간 자료형은 거의 key와 value쌍으로 이루어져 있다. 파이썬의 dict와 비슷하다.

선언 방법

    HashMap<String, Integer> map= new HashMap<String, Integer>();
    map.put("jun", 100);
    map.put("son", 200);
    System.out.println(map.get("jun"));