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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Do we need forward declarations in Java?
- Multidimensional Arrays in Java
- Multidimensional Collections in Java
- Initialize a list in a single line with a specified value using Java Stream
- Initialize a list in a single line with a specified value
- Set to Array in Java
- Anonymous array in Java
- Array vs ArrayList in Java
- Array set() method in Java
- Jagged Array in Java
- Array Copy in Java
- How to add an element to an Array in Java?
- List to array in Java
- Array of ArrayList in Java
- Array get() Method in Java
- Reverse an array in Java
- Array to Stream in Java
- Default array values in Java
- Program to convert Array to Set in Java
- Conversion of Array To ArrayList in Java