Collection.min Query For HashMap?
I have Declared a HashMap as
HashMap minMaxVal = new HashMap();
with K,V as Integer,Float[]Would Like to retrieve the Min value from hashMap. Overriding the Min Function of collection is only solution for this scena开发者_如何学Pythonrio. How do I approach this.
Your Map<Integer, Float[]>
can be converted to a Set<Map.Entry<Integer, Float[]>>
using Map.entrySet()
. Once you have this set, you can use Collections.min()
to find the minimum value. Your comparator will have to decide how two Map.Entry<Integer, Float[]>
instances compare.
I could have given you an example, but you didn't say what min meant in your case.
see this question : Get minvalue of a Map(Key,Double)
expecially see how to use a custom comparator, cause float[] is not directly (nor easily) comparable.
精彩评论