Java中, HashSet的clear()方法:java.util.HashSet.clear()
作者: Arvin Chen
来源: Break易站(www.breakyizhan.com)
Java中的HashSet
以下是java.util.HashSet.clear()方法的声明。
Hash_Set.clear()
Java中, HashSet的clear()方法的实例
public class HashSetDemo{
public static void main(String args[])
{
// Creating an empty HashSet
HashSet set = new HashSet();
// Use add() method to add elements into the Set
set.add("Welcome");
set.add("To");
set.add("breakyizhan");
set.add("4");
set.add("breakyizhan");
// Displaying the HashSet
System.out.println("HashSet: " + set);
// Clearing the HashSet using clear() method
set.clear();
// Displaying the final Set after clearing;
System.out.println("The final set: " + set);
}
}
HashSet: [4, breakyizhan, Welcome, To]
The final set: []