开发者

Collection.min Query For HashMap?

开发者 https://www.devze.com 2023-03-27 04:27 出处:网络
I have Declared a HashMap as HashMapminMaxVal = 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 solut

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消