Types of Array in Java

Java 8Object Oriented ProgrammingProgramming

Java supports single dimensional and multidimensional arrays. See the example below:

Example

 Live Demo

public class Tester {
   public static void main(String[] args) {
      double[] myList = {1.9, 2.9, 3.4, 3.5};
      // Print all the array elements
      for (double element: myList) {
         System.out.print(element + " ");
      }
      System.out.println();
      int[][] multidimensionalArray = { {1,2},{2,3}, {3,4} };
      for(int i = 0 ; i < 3 ; i++) {
         //row
         for(int j = 0 ; j < 2; j++) {
            System.out.print(multidimensionalArray[i][j] + " ");
         }
         System.out.println();
      }
   }
}

Output

1.9 2.9 3.4 3.5
1 2
2 3
3 4
raja
Published on 07-Feb-2018 05:26:01

Advertisements