About 5,800,000 results
Open links in new tab
  1. 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 …

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

  3. How do I break out of nested loops in Java? - Stack Overflow

    May 20, 2009 · The following code shows an example of exiting from the innermost loop. In other works,after executing the following code, you are at the outside of the loop of 'k' variables and …

  4. Breaking out of a for loop in Java - Stack Overflow

    Mar 7, 2013 · In my code I have a for loop that iterates through a method of code until it meets the for condition. Is there anyway to break out of this for loop? So if we look at the code below, …

  5. What is the easiest/best/most correct way to iterate through the ...

    Jan 6, 2017 · Some ways to iterate through the characters of a string in Java are: Using StringTokenizer? Converting the String to a char[] and iterating over that. What is the …

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

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

    Foreach loop in java for a custom object list Asked 12 years, 11 months ago Modified 3 years, 7 months ago Viewed 173k times

  8. Java Main Game Loop - Stack Overflow

    9 Overall, it is a good loop, but there are a few missing aspects to what I have found in experience to be the best loop. You will eventually want to move to LWJGL or some other java game API, …

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

    Depending on the situation could use a for each loop or Java 8 streams.

  10. java - Should try...catch go inside or outside a loop? - Stack Overflow

    If the exception-handler takes flow outside the loop, then I feel it's clearest to place it outside the loop -- Rather than placing a catch clause apparently within the loop, which nevertheless …