일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 오라클
- String
- 윈도우 #단축키
- list
- 다형성
- html
- 연산자
- 파일 입출력
- array
- function
- 데이터베이스
- File 클래스
- jsp
- Event
- property
- Method
- 자바
- springframework
- spring
- 연락처 프로그램
- 상속
- JavaScript
- GUI
- 코틀린#클래스#상속
- jQuery
- css
- Java
- javaservlet
- 설치
- kotlin #return #jump
- 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 |