list.stream() .collect( Collectors.collectingAndThen( Collectors.toCollection( () -> new TreeSet<>(Comparator.comparing(e -> e.getId)) ), ArrayList::new ) );