티스토리 뷰
1. Create
// 1번 방법 Create : 데이터 생성.추가 , 일반적으로 아래 두가지 방법이 사용된다.
list.add(new Apple(10, "호랑이"));
Apple a1 = new Apple(20, "코끼리");
list.add(a1);
// 2번 방법 Create
for(int i = 0 ; i < 5 ; ++i) {
list.add(new Apple(i*10+20, "독수리"+i));
}
2. Reading
// Reading : 데이터를 끄집어내는 것, 즉, 데이터를 읽는 것을 말한다.
for (Apple item : list) {
// System.out.println(item); // 이렇게 출력하면 자신 고유의 번호가 출력된다.
item.output();
}
3. Update
// update : LinkedList의 값을 변경(갱신)한다.
// 2번째 인덱스 값 갱신
list.set(2, new Apple(99, "맘모스"));
for (Apple item : list) {
item.output();
}
4. Delete
// delete : LinkedList의 데이트를 삭제한다.
// LinkedList의 3번째 요소를 삭제
list.remove(3);
for (Apple item : list) {
item.output();
}
2019.07.22(월) [Test05 Project]
'Java' 카테고리의 다른 글
[JAVA] Casting(upCasting, doenCasting) (0) | 2019.07.23 |
---|---|
[JAVA] instanceof 연산자 (0) | 2019.07.23 |
[JAVA] LinkedList를 활용한 정렬(Collections, Comparator, Comparable) (0) | 2019.07.23 |
[JAVA] 자료구조 클래스 - LinkedList(연결리스트) (0) | 2019.07.22 |
[JAVA] Collection(List, Set, Map)의 종류와 이해 (0) | 2019.07.21 |
댓글