Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Arrays allow us to store multiple values in a single variable.
- They are distinguished from other variables using brackets: []
- int[] numbers;
- Array values consist of the keyword "new", followed by the type, followed by brackets with a number inside.
- numbers = new int[5];
- The number in the brackets determine how many indexes this array has.
- To access an index, you use brackets to determine which index you want to access.
- numbers[0] = 10;
- Arrays are indexed starting at 0.
- This means you can access indexes 0 to 4 from numbers, for a total of 5 values.
- numbers[0] = 10;
- numbers[1] = 10;
- numbers[2] = 10;
- numbers[3] = 10;
- numbers[4] = 10;
- Arrays have a special property: length
- It determines how many indexes there are.
- System.out.println(numbers.length); // prints 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement