提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取树映射
//package com.nowjava;//from n o w j a v a . c o m import java.util.Comparator; import java.util.TreeMap; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getTreeMap()); } public static TreeMap<Object, Object> getTreeMap() { return new TreeMap<Object, Object>(getComparator()); }/* 来自 NowJava.com - 时 代 Java*/ private static Comparator<Object> getComparator() { return new Comparator<Object>() { @SuppressWarnings("unchecked") @Override public int compare(final Object o1, final Object o2) { final Comparable<Object> c1 = (Comparable<Object>) o1; final Comparable<Object> c2 = (Comparable<Object>) o2; if (o1.getClass().equals(o2.getClass())) {