일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- NAS
- portfolio
- body
- mysql
- flaskframework
- pymongo
- synology
- mongodb
- OOP
- Algorithm
- POST
- frontend
- github
- flask
- venv
- beautifulsoup
- PYTHON
- CSS
- atlas
- java
- requests
- openapi
- Crawling
- get
- Project
- json
- backend
- CRUD
- javascript
- fetch
Archives
- Today
- Total
wisePocket
[JAVA] 기초문법 - 자료구조 컬렉션 ArrayList 생성과 메서드 기능 이용 연습 - 21 본문
Java & Algorithm/Java
[JAVA] 기초문법 - 자료구조 컬렉션 ArrayList 생성과 메서드 기능 이용 연습 - 21
ohnyong 2023. 7. 27. 19:43Collection - ArrayList
ArrayList를 복습하고자 한다.
- ArrayList - 순서가 있는 데이터의 집합, 중복을 허용
- Array와의 차이점은 Array는 생성시 길이(크기)(length)를 지정하는 정적 배열인데,
- ArrayList는 가변적으로 늘어난다 동적 배열이다.(연속된 공간 요청-생성)
- element, item이 혼용되어 사용되어 공식 홈페이지를 참고하니 각 자료구조마다 명칭을 다르게 부르는 것을 보았다.
- ArrayList, LinkedList, Queue, Set -> element (리스트 리스트 set et element)
- Stack -> item (쌓이는거 통과하는거 물건이니까 아이템)
- Map -> Key, Value 키맵 키맵 맵 키 밸류
- 항상 공식 문서를 확인하고 정확한 명칭을 기억하려 노력하자
- https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
1. 기본 생성법
E - the type of elements maintained by this set
ArrayList<E> name = new ArrayList<E>();
ArrayList<Integer> intList = new ArrayList<Integer>();
2. ArrayList의 메서드를 사용
.add(E e) : element 추가
//추가(c) //add(element) 메서드로 생성한 List에 element를 넣어보자. intList.add(99); intList.add(15); intList.add(3); //->[{99}, {15}, {3}]
.get(int idx) : idx의 element 찾기
//get(index) 메서드로 List의 index값을 통해서 List에 추가한 element를 찾아보자. System.out.println(intList.get(2)); //->{3} //toString() 메서드로 List 전체 element들을 조회 할 수 있다. System.out.println(intList.toString());
.set(int idx, E element) : idx에 element 수정//set(index, element) 메서드로 List의 대상 index의 element를 입력한 element로 변경하자. intList.set(1, 10); //->[{99}, {10} , {3}]
.remove(int idx) : idx의 element 삭제//삭제(d) //remove(index) 메서드로 List의 index값을 통해서 element를 삭제하자. intList.remove(2); System.out.println(intList.toString()); //->[{99}, {10}, {}]
.clear() : element 모두삭제//clear() 메서드로 List의 모든 element를 삭제하자. intList.clear(); System.out.println(intList.toString());
'Java & Algorithm > Java' 카테고리의 다른 글
[JAVA] 기초문법 - 자료구조 컬렉션 Stack 생성과 메서드 기능 이용 연습 - 23 (0) | 2023.07.27 |
---|---|
[JAVA] 기초문법 - 자료구조 컬렉션 LinkedList 생성과 메서드 기능 이용 연습 - 22 (0) | 2023.07.27 |
[JAVA] 기초문법 - 다차원 배열(Multidimensional Array) 생성과 초기화, 조회, 최대값, 최소값 연습 - 20 (0) | 2023.07.27 |
[JAVA] 기초문법 - 1차원 배열(Array) 생성과 초기화, 조회, 복사, Arrays 클래스 메서드 활용 - 19 (0) | 2023.07.26 |
[JAVA] 기초문법 - 메서드(Method)와 함수(Function) 용어 구분하기 - 18 (0) | 2023.07.26 |