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 email@example.com. 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 and Collections concepts with the Fundamentals of Java and Java Collections 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
- Java.util.TreeMap.descendingMap() and descendingKeyset() in Java
- Java.util.TreeMap.firstEntry() and firstKey() in Java
- Java.util.TreeMap.containskey() and containsValue() in Java
- Java.util.TreeMap.pollFirstEntry() and pollLastEntry() in Java
- Java.util.TreeMap.put() and putAll() in Java
- Java.util.TreeMap.floorEntry() and floorKey() in Java
- Java Swing | Translucent and shaped Window in Java
- Difference between Core Java and Advanced Java
- Difference between a Java Application and a Java Applet
- Difference between Java IO and Java NIO
- Difference between Java and Core Java
- Sort an array of pairs using Java Pair and Comparator
- Difference between length of Array and size of ArrayList in Java
- Difference between String and Character array in Java
- Check whether array has all identical elements using Arrays.asList() and HashSet in Java