- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The Iterating over Arrays in Java
To iterate over arrays in Java, you can simply use a for loop. Looping should be till the length of the array to display all the elements.
Example
Let us now see an example to iterate over arrays −
public class Demo { public static void main(String args[]) { int myArray[] = new int[5]; myArray[0] = 230; myArray[1] = 110; myArray[2] = 130; myArray[3] = 350; myArray[4] = 290; System.out.println("Array elements..."); for(int i=0; i < myArray.length; i++) { System.out.println(myArray[i]); } } }
Output
Array elements... 230 110 130 350 290
Example
We can also iterate over arrays using for loop −
public class Demo { public static void main(String args[]) { int myArray[] = new int[5]; myArray[0] = 15; myArray[1] = 3; myArray[2] = 40; myArray[3] = 30; myArray[4] = 7; System.out.println("Array elements..."); for(int ele: myArray) { System.out.println(ele); } } }
Output
Array elements... 15 3 40 30 7
- Related Articles
- Iterating over Arrays in Java
- Iterating over ArrayLists in Java
- Iterating over array in Java
- Iterating over Enum Values in Java
- How do you use ‘foreach’ loop for iterating over an array in C#?
- C++ Remove an Entry Using Key from HashMap while Iterating Over It
- C++ Remove an Entry Using Value from HashMap while Iterating over It
- How to avoid ConcurrentModificationException while iterating a collection in java?
- How to iterate over arrays and objects in jQuery?
- Golang Program To Iterate Over Each Element From The Arrays
- C++ Program to iterate over each element from the arrays
- Arrays in Java
- Iterating through a dictionary in Swift
- Assigning arrays in Java.
- Final Arrays in Java

Advertisements