One Dimensional Array :
It is a collection of variables of same type which is used by a common name.
One dimensional array declaration of variable:
We can write it in any way.
Now, if you declare your array like below:
Now, suppose we want to write multiple declaration of array variable then we can use it like this.
When we are declaring multiple variable of same time at a time, we have to write variable first then declare that variable except first variable declaration. There is no restriction for the first variable.
Now, when we are creating array it is mandatory to pass the size of array; otherwise we will get compile time error.
You can use new operator for creating an array.
Printing array :
100 100 100
Two Dimensional Array
Suppose, you want to create two dimensional array of int type data. So you can declare two dimensional array in many of the following ways:
Now, Suppose we want to write multiple declarations of array variable then you can use it like this.
Creating one dimensional array and two dimensional array without new operator:
20 100 100 100 100 100 100 100 100 100
Creating one dimensional array and two dimensional array using new operator:
0 0 0 100 100 100 100 100 100 100 100 100
This article is contributed by Twinkle Patel. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.