Create HashSet, Add Elements and Display These | Java Programs

Output:

*** HashSet Creation ***

The Hash Set: [Red, White, Pink, Yellow, Black, Green]

Click Here For Java Online Compiler

Solution:

/**
 *
 * @author Alee Ahmed Kolachi
 */
import java.util.HashSet;

public class DemoHashSet {

    public static void main(String[] args) {

        HashSet<String> h_set = new HashSet<>();

        h_set.add("Red");
        h_set.add("Green");
        h_set.add("Black");
        h_set.add("White");
        h_set.add("Pink");
        h_set.add("Yellow");
        System.out.println("*** HashSet Creation ***" + "\n");
        System.out.println("The Hash Set: " + h_set);
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon