Default array values in Java
If we don’t assign values to array elements, and try to access them, compiler does not produce error as in case of simple variables. Instead it assigns values which aren’t garbage.
Below are the default assigned values.
- boolean : false
- int : 0
- double : 0.0
- String : null
- User Defined Type : null
String array default values: null null null null null Integer array default values: 0 0 0 0 0 Double array default values: 0.0 0.0 0.0 0.0 0.0 Boolean array default values: false false false false false Reference Array default values: null null null null null
This article is contributed by Twinkle Tyagi .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.