import java.util.Iterator;이 코드를 실행하면 다음과 같은 결과가 나타납니다.
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap입니다.
import java.util.Map;
public class TreeMapFirstkey {
public static void main(String a[]){
// TreeMap
TreeMap을 만듭니다< 문자열, 정수> tmap = 새 트리맵< 문자열, 정수> ();
// TreeMap에 키-값 쌍 추가
tmap.put("Key1",8);
tmap.put("키2",6);
tmap.put("키3",11);
tmap.put("키4",7);
// 모든 입력 가져오기
Set set = tmap.entrySet();
// 목록을 탐색하기 위해 iterator 가져오기
Iterator itr = set.iterator();
// 목록의 모든 항목 표시
while(itr.hasNext()) {
Map.Entry mentry = (Map.Entry)itr.next();
System.out.print("키: "+mentry.getKey() + " - ");
System.out.println("값: "+mentry.getValue());
}
항목< 문자열,정수> ent = tmap.lastEntry()를 호출합니다.
System.out.println("마지막 키/값 요소: ");
System.out.println(ent.getKey()+" ==> "+ent.getValue());
}
}
key: Key1 - 값: 8참조:
key: Key2 - 값: 6
key: Key3 - 값: 11
key: Key4 - 값: 7
첫 번째 키/값:
Key4 ==> 7
Please disable your ad blocker and refresh the window to use this website.