I came across this questions:
Given:
public static Function<String,String> swap = s -> {
if(s.equals("A"))
return "N";
else
return s;
};
And given:
Set<String> set = Set.of("A", "J", "T", "C");
set = set.stream()
.map(swap)
.collect(Collectors.toSet());
for(String s : set){
System.out.print(s);
}
What is the output?
I can tell that the set will contain: N, J, T, C but the possible answers have a several permutation of those four letters.
According to the documentation: Collections.ToSet()
returns a collector that is unordered
, nothing in the documentation points to the possible new order of this Set.
My question
Am I missing anything in the doc that actually guarantees the order of elements in the new Set