How to declare an array in Java

You can declare an array in Java in 3 different ways.

Sample Java

int[] myArr = new int[5];
int[] myArr = {1,2,3,4,5};
int[] myArr = new int[]{1,2,3,4,5};

Please Share us:
Please rate this snippet

4 thoughts on “How to declare an array in Java

Leave a Reply