During preparation for Java exam, I encountered this problem:
public static Function<String, String> change = i -> {
if (i.equals("Au"))
return "Ne";
else
return i;
};
Set<String> someStrings = Set.of("Au", "Ja", "Ta", "Cy", "Cu");
someStrings = someStrings
.stream()
.map(change)
.map(n -> n.substring(0, 1))
.collect(Collectors.toSet());
for (String s : someStrings) {
System.out.print(s);
}
Answers to this question suggest that order of printing is important. But how one should determine order of printing in this case? My only guess it is reversed order of listing elements in Set.of() method.