Languages
[Edit]
EN

Java - loop through HashSet

0 points
Created by:
Dirask Community
6300

In this article, we would like to show you how to loop through the HashSet in Java.

Quick solution:

for (String item : myArrayList) {
    System.out.println(item);
}

 

Practical example

In this example, we print letters HashSet using for-each loop.

import java.util.*;

public class Example {

    public static void main(String[] args) {
        Set<String> letters = new HashSet<>();

        letters.add("A");
        letters.add("B");
        letters.add("C");

        for (String letter : letters) {
            System.out.println(letter);
        }
    }
}

Output:

A
B
C
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join