Similar question see: How to make HashMap work with Arrays as key?
But I need TreeMap like ((int key1, int key2) -> String)
, comparing key1
then comparing key2
.
My solution is:
Map<int[], String> map = new TreeMap<>(Comparator.
<int[]>comparingInt(key -> key[0]).thenComparingInt(key -> key[1]));
But when I need ((int key1, int key2, int key3) -> String
, I must write more.
Is there a way to generate the Comparator for arrays with arbitrary length?
Comparator
that does exactly that. I doubt that could be reasonably and understandably done with lambdas. If you can do it with a lambda, go for it, but personally I'd just use regular Java. – Lagunas