Set<String> treeSet = new TreeSet<>();
//线程安全的集合
Set<String> syncTreeSet = Collections.synchronizedSet(treeSet);
treeSet.add("one");
treeSet.add("two");
treeSet.add("three");
for (String str:treeSet) {
System.out.println(str);
}
treeSet.remove("one");
treeSet.clear();
treeSet.isEmpty();
Set<String> hashset = new HashSet<>();
hashset.add("first");
hashset.contains("first");
hashset.stream().forEach(System.out::println);
hashset.remove("first");
hashset.clear();
hashset.isEmpty();
Set的一些常用操作
最新推荐文章于 2023-06-15 18:55:53 发布