collection
-
Map계열의 Collections / HashMap / 2019-12-09JAVA 2020. 1. 15. 12:08
Map 계열 - K : 키(Key) / V : 값(Value)를 의미 - 내부적으로 Map.Entry 라는 내부클래스 형태로 저장됨 => 키와 값으로 구성된 Entry(클래스) 객체의 모임 - 키는 중복 O, 값은 중복 X - HashMap을 많이 사용 Map map = new HashMap(); map.put(1, "바나나"); map.put(2, "딸기"); System.out.println(map); System.out.println("3번 key에 포도 등록 : " + map.put(3, "포도")); //원래 들어있던 값을 리턴(null리턴) System.out.println(map); {1=바나나, 2=딸기} 3번 key에 포도 등록 : null {1=바나나, 2=딸기, 3=포도} 값이 들어있..
-
List 계열의 Collection / List 인터페이스 / ArrayList / LinkedList / 2019-12-09카테고리 없음 2020. 1. 15. 11:16
List 계열은 인덱스 기반으로 데이터를 저장한다 (0~...) => 데이터 중복 허용 - null 값도 저장 가능 ArrayList list = new ArrayList(); list.add(1); list.add("TWO"); list.add(3.14); if (!list.isEmpty()) { System.out.println("list의 size : " + list.size());// list의 크기 System.out.println("list : " + list); } System.out.println("list 객체에 정수 1추가가 가능한가? : " + list.add(1)); System.out.println(list); list.add("4"); list.add(5L); System.out..