Java - 트리맵에서 모든 요소 삭제

메서드 clear()은 Java의 맵 구조에서 모든 요소를 제거하는 데 사용됩니다. 이 메서드를 호출한 후 목록 TreeMap은 비어 있습니다.

package codeurjava. 트리맵; 

import java.util.TreeMap;

public class TreeMapCopy {

public static void main(String a[]){
TreeMap hmap = new TreeMap();
//키-값 추가 peers
hmap.put(1, "one");
hmap.put(2, "둘");
hmap.put(3,"셋");
hmap.put(4,"넷");
hmap.put(5,"다섯");
hmap.put(6,"여섯");

System.out.println("이전 트리맵: "+hmap);

System.out.println("빈 트리맵");
hmap.clear();

System.out.println("이후 트리맵: "+hmap);
}
}
런타임:

TreeMap 이전: {1=하나, 2=둘, 3=셋, 4=넷, 5=5, 6=6}
빈 TreeMap
TreeMap 이후: {}