java操作Set集合
import java.util.HashSet; import java.util.Set; public class SetExample { public static void main(String[] args) { // 创建一个HashSet对象 Set<String> set = new HashSet<>(); // 添加元素 set.add("apple"); set.add("banana"); set.add("orange"); // 查找元素 String apple = "apple"; boolean found = set.contains(apple); System.out.println(apple + " found in set: " + found); // 移除元素 set.remove("banana"); // 遍历集合 for (String s : set) { System.out.println(s); } } }
###############
标签:set,java,apple,add,Set,集合,String From: https://www.cnblogs.com/herd/p/17363151.html