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 strings with HashSet in Java

2 Answers

0 votes
import java.util.HashSet;
 
public class MyClass {
    public static void main(String args[]) {
        HashSet<String> hs =new HashSet<String>();
         
        hs.add("java");
        hs.add("c");
        hs.add("php");
        hs.add("python");
        hs.add("java");

        System.out.println(hs);
    }
}
 
/*
run:

[python, java, c, php]
 
*/

 



answered Feb 8, 2019 by avibootz
0 votes
import java.util.*;
 
public class MyClass {
    public static void main(String args[]) {
        HashSet<String> hs =new HashSet<String>();
         
        hs.add("java");
        hs.add("c");
        hs.add("php");
        hs.add("python");
        hs.add("java");

        Iterator it = hs.iterator();
        while(it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
 
/*
run:

python
java
c
php
 
*/

 



answered Feb 8, 2019 by avibootz

Related questions

1 answer 145 views
145 views asked Nov 30, 2016 by avibootz
2 answers 225 views
1 answer 145 views
145 views asked Jan 16, 2022 by avibootz
1 answer 112 views
112 views asked Nov 9, 2021 by avibootz
1 answer 152 views
3 answers 81 views
...