About 39,400,000 results
Open links in new tab
  1. Iterate Over a Set in Java - Baeldung

    May 11, 2024 · The most basic and close-to-metal method of iterating over the set is invoking the iterator method exposed by every Set: Set<String> names = Sets.newHashSet("Tom", "Jane", …

  2. How to Iterate over a Set/HashSet without an Iterator?

    Feb 13, 2017 · You can use an enhanced for loop: Set<String> set = new HashSet<String>(); //populate set for (String s : set) { System.out.println(s); } Or with Java 8: …

  3. Java Program to Iterate over a Set

    System.out.println("Iterating over Set using for-each loop:"); for(String language : languages) { System.out.print(language); System.out.print(", "); Output. In the above example, we have …

  4. How do I iterate and modify Java Sets? - Stack Overflow

    You can safely remove from a set during iteration with an Iterator object; attempting to modify a set through its API while iterating will break the iterator. the Set class provides an iterator …

  5. Different Ways to Iterate over a Set in Java - Java Guides

    In this guide, we covered various methods to iterate over a Set in Java: Enhanced For-Loop: Simplifies code and improves readability. Iterator: Allows element removal during iteration. …

  6. 3 ways to loop over Set or HashSet in Java? Examples - Blogger

    Sep 11, 2021 · Here is a sample program to show you how you can loop over a Set in Java using both Iterator and advanced for loop. The only difference in the two ways is that you can …

  7. Best way to iterate through a Set in Java - Stack Overflow

    Sep 28, 2017 · Currently, i am using a normal for loop with iterator. ListMetadataElem element = (ListMetadataElem) iterator.next(); . NameValueObject value = new NameValueObject(); . …

  8. 6 Ways to Iterate or Loop Over Sets or HashMaps in Java

    Jun 11, 2024 · Iterating over Sets in Java is straightforward, with multiple techniques available to suit different scenarios. Whether you're using the traditional Iterator, the concise enhanced for …

  9. How to Loop Through a Set or HashSet Without Using an Iterator?

    In Java, there are several ways to iterate over a Set or HashSet without using the Iterator explicitly. One of the most common approaches is to utilize the enhanced for-loop, also known …

  10. Java 8 forEach with List, Set and Map Examples - Java Guides

    In real projects, we can use the forEach() method to loop over Java Classes to convert. Let's create Entity class and EntityDTO class, loop over a list of entities, and convert from Entity to …

  11. Some results have been removed
Refresh