I have an object called Instance with 2 fields, an array of features (which is another object) that represent columns in a dataset, such as age, sex, class, etc; and their values (i.e a number). I also have implemented a custom comparator that can sort a list of these objects based on a particular feature of the instance as follows:
Comparator<Instance> comparator = Comparator.comparing(c -> c.get(feature));
Instance[] sorted = instList.stream().sorted(comparator).toArray(Instance[]::new);
Now, this code works fine, however, there are many cases in which the feature that I am sorting by has the same value as another instance. In this case, how does Java decide how to continue sorting the list?