What does `Collectors.toCollection(TreeSet::new)` do?

  1. Returns a HashSet
  2. Returns a TreeSet containing sorted elements
  3. Returns a List
  4. Returns a Map
Correct answer Returns a TreeSet containing sorted elements

Explanation

`Collectors.toCollection(TreeSet::new)` collects elements into a TreeSet (sorted set).

Update: Admin added a tag on this question

Topics

By Admin · · 33 views