Default Array Values in Java Last Updated : 24 Jan, 2022 Comments Improve Suggest changes Like Article Like Report If we don't assign values to array elements and try to access them, the compiler does not produce an error as in the case of simple variables. Instead, it assigns values that aren't garbage. Below are the default assigned values. S. No.DatatypeDefault Value1booleanfalse2int03double0.04Stringnull5User-Defined Typenull Example: Java // Java program to demonstrate default // values of array elements class ArrayDemo { public static void main(String[] args) { System.out.println("String array default values:"); String str[] = new String[5]; for (String s : str) System.out.print(s + " "); System.out.println( "\n\nInteger array default values:"); int num[] = new int[5]; for (int val : num) System.out.print(val + " "); System.out.println( "\n\nDouble array default values:"); double dnum[] = new double[5]; for (double val : dnum) System.out.print(val + " "); System.out.println( "\n\nBoolean array default values:"); boolean bnum[] = new boolean[5]; for (boolean val : bnum) System.out.print(val + " "); System.out.println( "\n\nReference Array default values:"); ArrayDemo ademo[] = new ArrayDemo[5]; for (ArrayDemo val : ademo) System.out.print(val + " "); } } OutputString 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 Comment More infoAdvertise with us Next Article Default Array Values in Java T Twinkle Tyagi Improve Article Tags : Java Practice Tags : Java Similar Reads Default Methods In Java 8 Before Java 8, interfaces could only have abstract methods. The implementation of these methods has to be provided in a separate class. So, if a new method is to be added in an interface, then its implementation code has to be provided in the class implementing the same interface. To overcome this i 3 min read Default constructor in Java Like C++, Java automatically creates default constructor if there is no default or parameterized constructor written by user, and (like C++) the default constructor automatically calls parent default constructor. But unlike C++, default constructor in Java initializes member data variable to default 1 min read Can We Override Default Method in Java? Default method in Java is a method in java which are defined inside the interface with the keyword default is known as the default method. It is a type of non-abstract method. This method is capable of adding backward capability so that the old interface can grasp the lambda expression capability. J 3 min read Java.Lang.Float class in Java Float class is a wrapper class for the primitive type float which contains several methods to effectively deal with a float value like converting it to a string representation, and vice-versa. An object of the Float class can hold a single float value. There are mainly two constructors to initialize 6 min read HashMap values() Method in Java The java.util.HashMap.values() method of HashMap class in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the HashMap. Syntax: Hash_Map.values() Parameters: The method does not accept any parameters. Return Value: The method i 2 min read Java.Lang.Double Class in Java Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa. An object of the Double class can hold a single double value. Double class is a wrapper class for the pr 4 min read AbstractMap values() Method in Java with Examples The AbstractMap.values() method of AbstractMap class in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the AbstractMap. Syntax: AbstractMap.values() Parameters: The method does not accept any parameters. Return Value: The met 2 min read Instance Variable as Final in Java As we all know, when the value of a variable varies from object to object, then that type of variable is known as an instance variable. The instance variable is declared inside a class but not within any method, constructor, or block.If we don't initialize an instance variable, then the JVM automati 3 min read Final Static Variable in Java When the value of a variable is not varied, then it is not a good choice to go for an instance variable. At that time, we can add a static modifier to that variable. Whenever we declare a variable as static, then at the class level, a single variable is created which is shared with the objects. Any 3 min read Replace null values with default value in Java Map Given a Map with null values in it, the task is to replace all the null values with a default value. Examples: Input: map = {1=1, 2=2, 3=null, 4=4, 5=null, 6=null}, defaultValue = 0 Output: {1=1, 2=2, 3=0, 4=4, 5=0, 6=0} Input: map = {1=A, 2=B, 3=null, 4=D, 5=null, 6=null}, defaultValue = 'Z' Output 3 min read Like