Arrays and strings in a nutshell
In Java, arrays are objects and are dynamically created. Arrays can be assigned to variables of the Object
type. They can have a single dimension (for example, m[]
) or multiple dimensions (for example, as a three-dimensional array, m[][][]
). The elements of an array are stored starting with index 0, so an array of length n stores its elements between indexes 0 and n-1 (inclusive). Once an array object is created, its length never changes. Arrays cannot be immutable except for the useless array of length 0 (for example, String[] immutable = new String[0]
).
In Java, strings are immutable (String
is immutable). A string can contain ASCII characters (unprintable control codes between 0-31, printable characters between 32-127, and extended ASCII codes between 128-255) and Unicode characters. Unicode characters less than 65,535 (0xFFFF) are represented in Java using the 16-bit char
data type (for example, calling charAt(int index)
works as expected –...