集册 Java实例教程 获取树映射

获取树映射

欢马劈雪     最近更新时间:2020-01-02 10:19:05

635
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取树映射


//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())) {

          
展开阅读全文