Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to use HashSet in Java

1 Answer

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

public class MyClass {
    public static void main(String args[]) {
        HashSet<String> hs = new HashSet<String>();              

        hs.add("java");
        hs.add("c");
        hs.add("c++");
        hs.add("c#");
        hs.add("python");
        hs.add("php");

        Iterator<String> itr = hs.iterator();
        while(itr.hasNext()) {
            System.out.println(itr.next());
        }

    }   
}




/*
run:

c#
c++
python
java
c
php

*/

 



answered Nov 9, 2021 by avibootz

Related questions

1 answer 145 views
145 views asked Jan 16, 2022 by avibootz
2 answers 210 views
210 views asked Feb 8, 2019 by avibootz
1 answer 152 views
2 answers 225 views
3 answers 81 views
2 answers 108 views
1 answer 105 views
105 views asked Jul 23, 2023 by avibootz
...