What is an array and what is it used for?


An array is a data container which holds a fixed length of elements of homogeneous data type. It is used to store the elements of the same datatype.

Example

Live Demo

public class ArrayExample {
   public static void main(String args[]){
      int myArray[] = {44, 69, 89, 635};
      
      for (int i = 0; i<myArray.length; i++){
         System.out.println(myArray[i]);
      }
   }
}

Output

44
69
89
635

Updated on: 30-Jul-2019

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements