简体   繁体   中英

How to calculate min/max keys of map?

I have an array of elements where each element is of type Map

在此处输入图片说明

How to find Minimum and Maximum of Keys of a Map<String,float>

在此处输入图片说明

My Code :

在此处输入图片说明

Please help.

May be you can use Comparator and you create ascending order value arraylist

public static ArrayList<ObjectA> getObjectAList() {

    ArrayList<ObjectA> objectAList = new ArrayList<>();
    Collections.sort(objectAList, ObjectA.objectAValue);

    return objectAList;
}
public class ObjectA{
/* Comparator for sorting the list by value */
public static Comparator<ObjectA> objectAValue = new Comparator<ObjectA>() {

    @Override
    public int compare(ObjectA object1, ObjectA object2) {

        float value1 = object1.getValue();
        float value2 = object2.getValue();

        /* For ascending order */
        return Float.floatToIntBits(value1)-Float.floatToIntBits(value2);

    }
};

}

I have an array of elements where each element is of type Map

在此处输入图片说明

How to find Minimum and Maximum of Keys of a Map<String,float>

在此处输入图片说明

My Code :

在此处输入图片说明

Please help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM