About 352,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 foreach loop. …

  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. java - Is there a performance difference between a for loop and a for ...

    It uses the enhanced for loop syntax introduced in version 1.5 of the Java programming language. So, you should use the enhanced for loop by default, but consider a hand-written counted loop for …

  4. 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

  5. Is there a way to access an iteration-counter in Java's for-each loop ...

    Java 8 introduced the Iterable#forEach() / Map#forEach() method, which is more efficient for many Collection / Map implementations compared to the "classical" for-each loop.

  6. How do I apply the for-each loop to every character in a String?

    Mar 16, 2010 · So I want to iterate for each character in a string. So I thought: for (char c : "xyz") but I get a compiler error: MyClass.java:20: foreach not applicable to expression type How can I do this?

  7. object - Java: For-Each loop and references - Stack Overflow

    Jul 13, 2015 · 15 Java works a little bit different than many other languages. What o is in the first example is simply a reference to the object. When you say o = new MyObject(), it creates a new …

  8. Loop (for each) over an array in JavaScript - Stack Overflow

    Feb 17, 2012 · This question is similar to: Loop through an array in JavaScript. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that …

  9. Java 8 Iterable.forEach () vs foreach loop - Stack Overflow

    May 19, 2013 · The advantage of Java 1.8 forEach method over 1.7 Enhanced for loop is that while writing code you can focus on business logic only. forEach method takes java.util.function.Consumer …

  10. 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 which suggests the …