Array ( type[] )
Try it yourself →Fixed-size collection of elements.
Syntax
type[] name = {e1, e2, ...};Description
Arrays have a fixed size. Elements are accessed with 0-based indexing. Size is obtained with length (without parentheses).
Example
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] numbers = {10, 20, 30};
System.out.println(numbers[0]);
System.out.println(numbers.length);
}
}Expected output
10 3
When to use?
Fixed number of values.
Common mistakes
- ⚠️ In arrays, length is a PROPERTY (no parentheses); in Strings, length() is a method.