Sunday, 18 December 2022

Java Collections- SET

  Write a program using hashset to add the a,b,c alphabet and remove the c alphabet and  displayed the set and size of this set.



import java.util.HashSet;

public class simplehashset {
    public static void main(String[ ] args) {
        HashSet<String> set = new HashSet<String>();
        set.add("A");
        set.add("B");
        set.add("C");
        System.out.println(set);
        set.remove("A");
        System.out.println(set);

        System.out.println(set.size());
       
    }
}


OUTPUT: 
[A, B, C]
[B, C]
2


No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...