Say you are provided with a List<KVPair> , where each KVPair has String key , String Value and .equals() methods that do everything right.
How would you confirm that each of the elements in the list is similar to the other, or see if there is at least one?
In other words, if we have
KVPair kvp1 = new KVPAir("key", "value"); KVPair kvp2 = new KVPAir("key", "value"); List<KVPair> l = new ArrayList<KVPair>(); l.add(kvp1); l.add(kvp2);
One approach I can think of is to sort the list first and iterate to the next, like the previous one.
Is there an easier and clearer way to find the same?
source share