Which collector would be best to collect elements into a `TreeSet`?

  1. Collectors.toSet()
  2. Collectors.toTreeSet()
  3. Collectors.toCollection(TreeSet::new)
  4. Collectors.groupingBy(TreeSet::new)
Correct answer Collectors.toCollection(TreeSet::new)

Explanation

`Collectors.toCollection(TreeSet::new)` is used to collect elements into a TreeSet.

By Ram Sharma · · 24 views