How to add items to set in Java

1 Answer

0 votes
import java.util.Set;
import java.util.HashSet;

public class MyClass {
    public static void main(String args[]) {
        Set<String> st = new HashSet<String>();
  
        st.add("java");
        st.add("c");
        st.add("c");
        st.add("c");
        st.add("c++");
        st.add("c++");
        st.add("python");
  
        System.out.println(st);
    }
}
 
 
 
 
 
/*
run:
  
[c++, python, java, c]
  
*/

 



answered Sep 29, 2022 by avibootz

Related questions

1 answer 105 views
105 views asked Feb 27, 2024 by avibootz
1 answer 153 views
153 views asked Sep 18, 2022 by avibootz
1 answer 188 views
1 answer 134 views
2 answers 213 views
1 answer 167 views
...