package edu.exam13.ex09tree_map;

import java.util.Iterator;
import java.util.NavigableSet;
import java.util.TreeMap;

public class UseTreeMap {
	public static void main(String[] args) {
		TreeMap<Integer, String> tMap =
				new TreeMap<Integer, String>();
		tMap.put(1, "data1");
		tMap.put(3, "data3");
		tMap.put(5, "data5");
		tMap.put(2, "data2");
		tMap.put(4, "data4");
		tMap.put(0, "data0");
		
		System.out.println(tMap.get(3));
		System.out.println(tMap.get(5));
		tMap.remove(5);
		System.out.println(tMap.get(5));
		System.out.println("---------------------------");
		
		NavigableSet<Integer> navi = tMap.navigableKeySet();
		Iterator<Integer> itr = navi.iterator();
		while(itr.hasNext()) {
			int key = itr.next();
			System.out.println(key + ":" + tMap.get(key));
		}
		System.out.println("---------------------------");
		itr = navi.descendingIterator();	//내림차순 정렬
		while(itr.hasNext()) {
			int key = itr.next();
			System.out.println(key + ":" + tMap.get(key));
		}		
	}
}

'JAVA > java 예제' 카테고리의 다른 글

bytefile / bufferfile 예제  (0) 2020.01.29
stack queue 예제  (0) 2020.01.29
TreeSet 예제  (0) 2020.01.29
TreeSet 정렬 예제  (0) 2020.01.29
얕은복사 깊은복사 예제  (0) 2020.01.28

+ Recent posts