Types of Array in Java


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

Updated on: 30-Jul-2019

169 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements