java can set hold string as well? code example
Example 1: java how to make set
HashSet<String> set = new HashSet();
set.add("One");
set.add("Two");
set.remove("One");
set.clear();
Example 2: how to check how many elements in a set java
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class MainClass {
public static void main(String[] a) {
String elements[] = { "A", "B", "C", "D", "E" };
Set set = new HashSet(Arrays.asList(elements));
System.out.println(set.size());
}
}