Java TutorialLesson 19Free preview
Java Arrays
This lesson is part of Java · All levels
Summary
An array is a fixed container that holds several values of the same type in one name. Each element is accessed through an index that starts from 0 to the length of the array minus one. The size of the array is fixed since it was created, whereas for data that changes in length you can use the ArrayList.
Key points
- Declaration: type[] name = new type[length]; or directly with initial value {a, b, c}
- The array index starts at 0, so the last element is at length -1.
- Access to an index outside the range results in an ArrayIndexOutOfBoundsException
- The array can contain primitive types or objects like strings.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.