Advertisement
ipwxy

Arrays

Jun 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Arrays allow us to store multiple values in a single variable.
  2. They are distinguished from other variables using brackets: []
  3.  
  4. int[] numbers;
  5.  
  6. Array values consist of the keyword "new", followed by the type, followed by brackets with a number inside.
  7.  
  8. numbers = new int[5];
  9.  
  10. The number in the brackets determine how many indexes this array has.
  11. To access an index, you use brackets to determine which index you want to access.
  12.  
  13. numbers[0] = 10;
  14.  
  15. Arrays are indexed starting at 0.
  16. This means you can access indexes 0 to 4 from numbers, for a total of 5 values.
  17.  
  18. numbers[0] = 10;
  19. numbers[1] = 10;
  20. numbers[2] = 10;
  21. numbers[3] = 10;
  22. numbers[4] = 10;
  23.  
  24. Arrays have a special property: length
  25. It determines how many indexes there are.
  26.  
  27. System.out.println(numbers.length); // prints 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement