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