Skip to main content
Array in java

Array is a variable that can hold
more than one value at a time.

Declaration :
   int arr[] = {elements}
   or
   int [] arr = {elements}

Intialization :
   int arr[] = {2, 4, 6, 7,}
 
  Example :

   public class arrLesson {
       
       public static void main(String           args[]) {
               // declares an array
               int arr[] = { 2, 3, 2, 9, 3 };
             
                  for(int i=0; i < arr.length;       i++)      {   
                  /* outputs each element
                      of the array */
                 System.out.println( arr[i] );
              }
 

        }

}

result :
2
3
2
9
3

Comments