This example shows how to create a Set and add objects to it.
Unlike classes implementing the List interface, a Set class doesn't allow the same value to be stored twice.
import java.util.HashSet;
import java.util.Set;
public class HashSetExample {
/**
* Example method for using a Set
*/
public void hashSetExample() {
Set personType = new HashSet();
//Add the items to the Set
personType.add("student);
personType.add("employee);
personType.add("pensioner);
}
}
No comments:
Post a Comment