If I run this code:
public class Main {
public static void main(String[] args) {
Collection<String> set = new ArrayList<String>();
set.add("b");
set.add("a");
set.add("c");
set.add("c");
set.stream().collect(Collectors.toSet());
System.out.println(set);
}
}
I will get [b,a,c,c]. But if I right, previous code should be short form of expression:
public class Main {
public static void main(String[] args) {
Collection<String> set = new ArrayList<>();
set.add("b");
set.add("a");
set.add("c");
set.add("c");
Collection<String> set2 = new HashSet<>(set);
System.out.println(set2);
}
}
And here, I got [a,b,c]
So, in example 1. Is it incorrect result or I do something wrong?