일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 다형성
- function
- 설치
- kotlin #return #jump
- Method
- list
- Event
- spring
- 코틀린#클래스#상속
- File 클래스
- array
- springframework
- css
- JavaScript
- 윈도우 #단축키
- 오라클
- Java
- 연산자
- 연락처 프로그램
- 파일 입출력
- GUI
- 데이터베이스
- 상속
- jsp
- String
- jQuery
- javaservlet
- 자바
- property
- html
- Today
- Total
Binary World
JAVA CLASS : Map-TreeMap 클래스 본문
<TreeMap 클래스>
* CollectionMain08.java
package edu.java.collection08; import java.util.Iterator; import java.util.Set; import java.util.TreeMap; // Map<K, V> // |__ HashMap<K, V>, TreeMap<K, V> public class CollectionMain08 { public static void main(String[] args) { // TreeMap<String, String> 객체 생성 TreeMap<String, String> map = new TreeMap<>(); // Map<K, V>에 데이터 저장: put<key, value) map.put("root", "root1234"); map.put("guest", "guest"); map.put("root2", "root1234"); System.out.println(map); System.out.println(); // 특정 키의 데이터 검색: get(key) System.out.println(map.get("root")); System.out.println(); // 특정 키의 데이터를 수정: put(key, value) map.put("root2", "root!@#$"); System.out.println(map); System.out.println(); // 특정 키의 데이터 삭제: remove(key) map.remove("root2"); System.out.println(map); System.out.println(); // Map<K, V>에서 키값들로 이루어진 Set<E> 생성 Set<String> keys = map.keySet(); for (String k : keys) { System.out.println(k + "=" + map.get(k)); }
System.out.println(); // Map의 키들로 이루어진 집합(Set)에서 Iterator 객체 생성 Iterator<String> itr = keys.iterator(); while(itr.hasNext()){ String key = itr.next(); System.out.println(key + "=" + map.get(key)); } } } |
'개발자의 길 > JAVA' 카테고리의 다른 글
JAVA CLASS : Inner Class(내부 클래스) (0) | 2017.01.12 |
---|---|
JAVA CLASS : Inner Class (연습문제 4, 5) (0) | 2017.01.10 |
JAVA CLASS : Map-HashMap 클래스 (0) | 2017.01.09 |
JAVA CLASS : Set - TreeSet 클래스 (0) | 2017.01.09 |
JAVA CLASS : Set - HashSet 클래스 (0) | 2017.01.09 |