목록JAVA/chapter23_collection_framework (7)
WON.dev
Q1. Test01.java 게시물을 저장하는 Board 클래스를 정의하고, ArrayList를 이용하여 3개의 게시물을 저장하시오. 1~3번 게시물번호 중 하나를 입력 받아 해당 게시물을 삭제하시오. class Board필드 : String title, String content, Date register register -> 현재 날짜 자동 삽입 메소드 : 생성자, toString() Q2. Test02.java 로또 & 빙고 (빙고가 어려우면 로또부터 해보기) Set을 이용하여 5 X 5 Bingo 배열을 생성하시오. (1 ~ 25) Set에 랜덤 생성 -> Bingo 2차원 배열에 저장 package org.joonzis.test; //게시물을 저장하는 Board 클래스를 정의하고, ArrayLi..
package org.joonzis.ex; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Ex06_HashMap { public static void main(String[] args) { Map map = new HashMap(); // 데이터 추가 : put(key, value) map.put("할머니", 120); map.put("할아버지", 110); map.put("엄마", 70); map.put("아빠", 60); map.put("동생", 3); map.put("동생", 10);// key 중복 발생 (중복된 key를 삽입 시 기존 value가 ..
package org.joonzis.ex; import java.util.TreeSet; public class Ex05_TreeSet { public static void main(String[] args) { // TreeSet 의 메소드를 사용하기 위해 Set 대신 TreeSet 사용 TreeSet set = new TreeSet(); set.add("airplane"); set.add("apple"); set.add("area"); set.add("disc"); set.add("dance"); /* * 1. 메소드 정의 * * headSet : 지정된 객체보다 작은 값의 객체들 반환 * subSet: 범위 내의 검색 결과 반환 * tailSet: 지정된 객체보다 큰 값의 객체들 반환 */ Syst..
package org.joonzis.ex; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class Ex04_HashSet { public static void main(String[] args) { Set set = new HashSet(); set.add("C"); set.add("Spring"); set.add("Java"); set.add("DB"); set.add("JSP"); set.add("Web"); set.add("Java");// 중복 저장 시도 Iterator itr = set.iterator(); while(itr.hasNext()) { String str = itr.next(); i..
package org.joonzis.ex; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class Ex03_LinkedList { public static void main(String[] args) { /* * ArrayList 와 LinkedList 성능 비교 * 1000개의 객체를 0번 인덱스에 삽입하는데 걸리는 시간을 측정 * * - 순차적으로 추가/삭제하는 경우에는 ArrayList가 빠르지만, * 중간에 추가/삭제 하는 경우는 LinkedList가 더욱 빠르다. */ List list1 = new ArrayList(); List list2 = new LinkedList();// Arr..
package org.joonzis.ex; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Ex02_iterator { public static void main(String[] args) { List list = new ArrayList(); // 10, 20, 30,...100 까지 list에 저장하기 //for(int i=1; i
package org.joonzis.ex; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Ex01_ArrayList { public static void main(String[] args) { List list = new ArrayList(); //ArrayList list = new ArrayList(); // 1. 저장 : add() list.add(new Integer(1)); list.add(new Integer(2)); list.add(5); list.add(4); list.add(3); list.add(5,2);// 인덱스를 지정하여 값을 넣을 수 있다. add(인덱스 번호..