Java Map Sort sortByValue(Map map, Comparator aComp)

Here you can find the source of sortByValue(Map map, Comparator aComp)

Description

sort By Value

License

Open Source License

Declaration

public static Map sortByValue(Map map, Comparator aComp) 

Method Source Code


//package com.java2s;
/*/*from w w w . j  a  va2s.c  om*/
 * #%L
 * org.bml
 * %%
 * Copyright (C) 2006 - 2014 Brian M. Lima
 * %%
 * This file is part of ORG.BML.
 * 
 *     ORG.BML is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     ORG.BML is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with ORG.BML.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Main {
    public static Map sortByValue(Map map, Comparator aComp) {
        List list = new LinkedList(map.entrySet());
        Collections.sort(list, aComp);
        Map result = new LinkedHashMap();
        for (Iterator it = list.iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }
}

Related

  1. sortByValue(final Map map)
  2. sortByValue(final Map map)
  3. sortByValue(final Map map, final boolean asc)
  4. sortByValue(Map map)
  5. sortByValue(Map map)
  6. sortByValue(Map map)
  7. sortByValue(Map map)
  8. sortByValue(Map map)
  9. sortByValue(Map map)