I need your assiatance please:
I have a map :
Map<String, Object[]> data = new HashMap<String, Object[]>();
The Object[] array is built out of triples: [String, String, Integer]
Later on, I am going to read the object[] array values, but I should print them sorted according to the integer value.
How can I do this in the best way?
Thank you!
One way is with a stream:
data.values().stream()
.sorted(Comparator.comparing(a -> (Integer)a[2]))
.forEachOrdered(a -> System.out.println(Arrays.toString(a)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With