Back to Java Basics
This tutorial didn’t start with detailed coverage of basic constructs of the Java language such as the syntax of if statements, loops, and the like. You started learning Java programming with getting used to object-oriented terms and constructs of the language. This lesson is a grab bag of basic language elements, terms, and data structures.
An array is a data storage that’s used to store multiple values of the same type. Let’s say your program has to store names of 20 different girls, such as “Masha”, “Matilda”, “Rosa” and so on. Instead of declaring 20 different String variables, you can declare one String array with the capacity to store 20 elements:
String  friends = new String ; // Declare and instantiate array friends = "Masha"; //Initialize the first element friends = "Matilda"; //Initialize the second element friends = "Rosa"; // Keep initializing the elements of the array here friends = "Natasha"; //Initialize the last element
The first element of an array in Java always has an index of 0. While declaring an array you can place brackets either after the data type or after the variable name. Both of the following declarations are correct:
String friends; String friends;
You must know the size of the array before assigning values to its elements. If you want to be able to dynamically change the size of an array during the run time, consider other Java ...