I'm seeing an interesting behavior in stream processing of String arrays.
I'm doing something like this
String s = "1_2_string";
String[] arr = s.split("_");
final Set<String> CAST_PATTERN = Set.of("string", "string2");
Arrays.stream(arr)
.filter(id -> !CAST_PATTERN.contains(id))
.map(Long::valueOf)
.collect(Collectors.toSet());
Expected outcome should be a set [1,2] but actual outcome is [2,1] Collectors.toSet() creates an HashSet and not a SortedSet, so it should not mess up the order of data. Not sure why!!