About 136,000 results
Open links in new tab
  1. In detail, how does the 'for each' loop work in Java?

    } What would the equivalent for loop look like without using the for each syntax? People new to Java commonly encounter issues when trying to modify the original data using the new style …

  2. How do I get the current index/key in a "for each" loop

    16 In Java, you can't, as foreach was meant to hide the iterator. You must do the normal For loop in order to get the current iteration.

  3. How do I efficiently iterate over each entry in a Java Map?

    If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map? Will the ordering of

  4. java - Iterate through a HashMap - Stack Overflow

    Jul 1, 2009 · Since all maps in Java implement the Map interface, the following techniques will work for any map implementation (HashMap, TreeMap, LinkedHashMap, Hashtable, etc.) …

  5. loops - Ways to iterate over a list in Java - Stack Overflow

    730 Being somewhat new to the Java language I'm trying to familiarize myself with all the ways (or at least the non-pathological ones) that one might iterate through a list (or perhaps other …

  6. Foreach loop in java for a custom object list - Stack Overflow

    I am not a keen user of java but I know in many other programming languages a foreach loop would be the most simple way of doing this. After a bit of research I found the following link …

  7. java - How to for each the hashmap? - Stack Overflow

    300 Lambda Expression Java 8 In Java 1.8 (Java 8) this has become lot easier by using forEach method from Aggregate operations (Stream operations) that looks similar to iterators from …

  8. Break or return from Java 8 stream forEach? - Stack Overflow

    When using external iteration over an Iterable we use break or return from enhanced for-each loop as:

  9. Java Foreach with a condition - Stack Overflow

    Apr 11, 2012 · 8 No, foreach is specially designed only for iterating all the elements of an array or collection. If you want you can check condition inside it and use break keyword for getting out …

  10. Calling remove in foreach loop in Java - Stack Overflow

    Since the for-each loop hides the iterator, you cannot call the remove() directly. So in order to remove items from a for-each loop while iterating through it, have to maintain a separate list.