Skip to content

Defaults

When we create an array, Java fills it with default values.

Array default values

This is different than a local variable, which does not get a default value.

The default values for data types are listed below.

Type Default Value
int 0
double 0.0
char \u0000
boolean false
objects null
  • \u0000 is a unicode character, which we will explain later.
  • String is an example of an object.

Practice Exercise

The array variable itself must be initialized before use, but when the array is instantiated the elements are given default values.


Prev -- Up -- Next