Java中HashSet使用代码演示
import java.util.HashSet; public class myHashsetExample { public static void main(String[] args) { HashSet<String> languages = new HashSet<String>(); languages.add("hindi"); languages.add("english"); languages.add("spanish"); System.out.println("The number of languages is " + languages.size()); for (String name : languages) { System.out.println(name); } languages.remove("hindi"); languages.add("tamil"); String name = "hindi"; if (languages.contains(name)) { System.out.println(name + " is in the collection."); } else { System.out.println(name + " is not in the collection."); } for (String n : languages) { System.out.println(n); } languages.clear(); System.out.println("The number of languages is " + languages.size()); } }