I've noticed something strange about Collections.groupingBy. I know that the elements are not ordered but is there someone who can explain me the following scenarios:
public class A{
Integer index;
// Constructor
}
1. List<A> listOfA = Arrays.asList(new A(3), new A(1), new A(5));
System.out.println(listOfA.stream().collect(Collections.groupingBy(A::getIndex));
=> Will print 1, 3, 5 in an ordered way
2. List<A> listOfA = Arrays.asList(new A(1), new A(31), new A(5), new A(32));
System.out.println(listOfA.stream().collect(Collections.groupingBy(A::getIndex));
=> Will print 32, 1, 3, 5, 31 in an unordered way
Why 32 was added before 1 ?