how-to

Arrays

How to create array

Array you can create with more techniques.

VARIANT 1

Typical declarating and creating throught new operator.

/* creating */

String[] array = new String[3];

/* initialization */

array[0] = "One";
array[1] = "Two";
array[2] = "Three";

VARIANT 2

Creating by specifying array items.

String[] array = { "one", "two", "three" };

NOTE: Arrays are indexed from zero [0], so for array with three items you can use indexes 0..2. When you use non-existed index, is raised java.lang.ArrayIndexOutOfBoundsException exception.