标签:util ber hashset ring oid 好处 使用 add mil
如下的代码段是关于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());
}
}
标签:util ber hashset ring oid 好处 使用 add mil
原文地址:https://www.cnblogs.com/anemone/p/11452914.html