● Arrays represent groups of related data all of the identical data type.
● The size of an array is established when created and cannot be modified.
● Arrays can store either primitive data or object reference data.
● When an array is created using the keyword new, all of its elements are initialized with a specific value based on the type of elements:
o Elements of type int are initialized to 0
o Elements of type double are initialized to 0.0
o Elements of type boolean are initialized to false
o Elements of a reference type are initialized to the reference value null. No objects are automatically created.
● Square brackets ([ ]) are utilized to get to and adjust a component in an Array utilizing a list. The indexed value, for instance array[index], can be utilized anywhere a normal variable can be utilized, for instance to get or assign any values or variables.
● The valid index values for an array are 0 through one less than the size of the array. Utilizing a record and index value outside of this range will give you an ArrayIndexOutOfBoundsException.
● Iteration (loops) can be utilized to get to all the components in an array, traversing through the array.
● Traversing an array with an indexed for loop or while loop expects components to be accessed with their indices.
public class OffByone
{
public static void main(String[] args)
{
int[ ] scores = { 10, 9, 8, 7, 6};
// Make this loop print out all the scores!
for (int i = 1; i <= scores.length; i++)
{
System.out.println( scores[i] );
}
}
}
● Enhanced For Loop = For Each LLoop
o Can be used in an array without specifying an index variable.
● Determining the minimum or maximum value
● Computing a sum, average, or mode of elements
● Searching for an element in the array
● Insert elements in the ArrayList
● Delete elements in the ArrayList
● Determining whether there are duplicate/identical elements
● Changing the order of elements
● Reversing the order of elements