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 94 views
94 views asked Feb 27, 2024 by avibootz
1 answer 141 views
141 views asked Sep 18, 2022 by avibootz
1 answer 173 views
1 answer 117 views
2 answers 183 views
1 answer 154 views
...