- 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
How to loop through an array in Java?
To process array elements, we often use either for loop or for each loop because all of the elements in an array are of the same type and the size of the array is known. Suppose we have an array of 5 elements we can print all the elements of this array as −
Example
public class ProcessingArrays { public static void main(String args[]) { int myArray[] = {22, 23, 25, 27, 30}; for(int i=0; i<myArray.length; i++) { System.out.println(myArray[i]); } } }
Output
22 23 25 27 30
- Related Articles
- Loop through an array in Java
- How to use for each loop through an array in Java?
- How to use for...in statement to loop through an Array in JavaScript?
- How to loop through all the elements of an array in C#?
- Loop through an ArrayList using an Iterator in Java
- Loop through a HashMap using an Iterator in Java
- Loop through ArrayList in Java
- Loop through the Vector elements using an Iterator in Java
- How do you loop through a C# array?
- Loop through an index of an array to search for a certain letter in JavaScript
- How do we use foreach statement to loop through the elements of an array in C#?
- How to loop through all values of an enum in C#?
- Java Program to loop through Map by Map.Entry
- Loop through array and edit string JavaScript
- Recursively loop through an array and return number of items with JavaScript?

Advertisements