JDK9中的Set.of()使用注意 考虑考虑 2026-06-01 0 阅读1分钟 前言 JDK9中的Set.of()创建是不能有重复元素的,否则会报错 Set.of()使用注意 public class Set1Demo { static void main() { Set<Integer> set = Set.of(1, 1, 2, 3, 4, 5); System.out.println(set); } } 输出结果为 总结 JDK9中的Set.of()创建是不能有重复元素的,否则会报错