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

    People new to Java commonly encounter issues when trying to modify the original data using the new style foreach loop. Use Why doesn't assigning to the iteration variable in a foreach loop …

  2. What is the syntax of the enhanced for loop in Java?

    Mar 2, 2017 · I have been asked to use the enhanced for loop in my coding. I have only been taught how to use traditional for loops, and as such don't know about the differences between …

  3. java - Declaring variables inside or outside of a loop - Stack Overflow

    Jan 10, 2012 · The scope of local variables should always be the smallest possible. In your example I presume str is not used outside of the while loop, otherwise you would not be asking …

  4. java - How does a for loop work, specifically for (;;)? - Stack Overflow

    Jul 23, 2015 · loop body: The body of the loop, which will be executed again and again based on the conditional check's truth value. Basically this is how the execution follows - first, when the …

  5. java - when to use while loop rather than for loop - Stack Overflow

    A for loop is just a special kind of while loop, which happens to deal with incrementing a variable. You can emulate a for loop with a while loop in any language. It's just syntactic sugar (except …

  6. What are the advantages of Enhanced for loop and Iterator in Java?

    Jul 25, 2010 · The for-each loop is almost certainly the most new popular feature from Java 5. It works because it increases the abstraction level - instead of having to express the low-level …

  7. What is the difference between i++ & ++i in a for loop?

    The way for loop is processed is as follows 1 First, initialization is performed (i=0) 2 the check is performed (i < n) 3 the code in the loop is executed. 4 the value is incremented 5 Repeat steps …

  8. Is there a shorter way to write a for loop in Java?

    If you spent 25 years reading for loops, you can spend for example 2 days to get into lambda functions in java and streams. It is really useful.

  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 …

  10. 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 …