Java 将 Int Array 转换为 SortedSet

mat*_*th5 3 java arrays collections spring-boot

如何将 int 数组转换为 SortedSet?

以下不起作用,

SortedSet lst= new TreeSet(Arrays.asList(RatedMessage));
Run Code Online (Sandbox Code Playgroud)

错误:

无法在 java.util.TreeMap.compare(TreeMap.java:1290) 处转换​​为 java.lang.Comparable

ole*_*nik 7

public static NavigableSet<Integer> convertToSet(int... arr) {
    return Arrays.stream(arr).boxed().collect(Collectors.toCollection(TreeSet::new));
}
Run Code Online (Sandbox Code Playgroud)