About 128,000 results
Open links in new tab
  1. loops - Ways to iterate over a list in Java - Stack Overflow

    Essentially, there are only two ways to iterate over a list: by using an index or by using an iterator. The enhanced for loop is just a syntactic shortcut introduced in Java 5 to avoid the tedium of explicitly defining an iterator.

  2. Convert Java Array to Iterable - Stack Overflow

    The ONLY way to create an existing Collection derivative implementing Iterable is to use a loop (except you use anonymous classes as described above) or you instantiate an Iterable implementing class whose constructor allows a primtive type array (because Object[] doesn't allow arrays with primitive type elements) but as far as I know, the Java ...

  3. java - JSON - Iterate through JSONArray - Stack Overflow

    I want to iterate though the objects in the array and get thier component and thier value. In my example the first object has 3 components, the scond has 5 and the third has 4 components. I want iterate though each of them and get thier component name and value. The following code does exactly that.

  4. java - Iterate through 2 dimensional array - Stack Overflow

    Sep 12, 2014 · These functions should work. // First, cache your array dimensions so you don't have to // access them during each iteration of your for loops. int rowLength = array.length, // array width (# of columns) colLength = array[0].length; // array height (# of rows) // This is your function: // Prints array elements row by row var rowString = ""; for(int x …

  5. Iterate through string array in Java - Stack Overflow

    Oct 25, 2014 · Printing the contents both of the list and the array (Arrays.toString(array)) results in: [a+b, b+c, c+d, d+e] Java 8. As of Java 8, you might be tempted to use the advantage of Stream API, however, it was made for procesing the individual elements from a source collection. There is no such method for processing 2 or more sibling nodes at once.

  6. Fastest way to iterate an Array in Java: loop variable vs enhanced …

    If you're looping through an array, it shouldn't matter - the enhanced for loop uses array accesses anyway. For example, consider this code:

  7. java - Iterate over int array - Stack Overflow

    Oct 16, 2017 · "You can't modify an array using an enhanced-for loop" isn't true. We can still modify array, but not via list[x]=x. If we declare our own iteration counter we can still use list[iteration++]=newValue; even inside enhanced-for loop. –

  8. Java int [] [] array - iterating and finding value - Stack Overflow

    Jan 23, 2009 · I have an array in the form of 'int[][]' that represents the co-ordinates of a small grid. Each co-ordinate has been assigned its own value. eg array[0][4] = 28..... I have two questions. Firstly, how do I iterate through all the stored values. Secondly, I want to be able to input a value and have its specific co-ordinates in the grid returned.

  9. Iterating Java Arrays in Java 8 - Stack Overflow

    Oct 31, 2017 · Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n). For example, given [1,2,3,4], return [24,12,8,6].

  10. Java loop over Json array? - Stack Overflow

    Sep 26, 2013 · In your code the element dataArray is an array of JSON objects, not a JSON object itself. The elements A , B , and C are part of the JSON objects inside the dataArray JSON array. You need to iterate over the array

Refresh