| English | 意味 |
|---|---|
| initializer list/ɪˈnɪʃəlaɪzə lɪst/ | 初期化リスト |
| ArrayIndexOutOfBoundsException/əˈreɪ ˈɪndeks ˈaʊtəv baʊndz ekˈsepʃn/ | ArrayIndexOutOfBoundsException |
Making an array
- Declare an array with a type and
[]:int[] scores; - Create it with
newand a size:int[] scores = new int[5];(five slots). - Or list the values directly:
int[] scores = {85, 90, 78};(an initializer list 初始化列表). - Every slot starts at the type's default (
0forint,nullfor objects).
Indexing from zero
- Array elements are numbered from
0; the last index islength - 1. - Access a slot with
scores[i]:scores[0]is the first,scores[2]the third. - Assign with
scores[0] = 100;and read withint x = scores[0];. - Off-by-one on the last index is the most common array bug.

A one-dimensional array (a list) with its indices and bounds
The length field
- An array's size is its
lengthfield — no parentheses:scores.length. - (Contrast
String'slength()method, which has parentheses.) lengthis fixed once the array is created — arrays don't resize.- Use
scores.lengthin loop conditions to stay in bounds.
Out of bounds
- A valid index is
0tolength - 1; anything else throws an ArrayIndexOutOfBoundsException 数组下标越界异常. scores[5]on a length-5 array is out of bounds (indices are0–4).- The loop condition
i < scores.lengthkeepsiin range. - Never use
<=withlength— it steps one past the end.
Array size is length (a field, NO parentheses); String length is length() (a method, WITH parentheses). Mixing them up won't compile. And valid indices are 0 to length - 1 — scores[scores.length] is one past the end and throws an ArrayIndexOutOfBoundsException. Loop with i < scores.length, never i <= scores.length.
Creating and accessing an array:
int[] a = {10, 20, 30};— length3, indices0,1,2.a[0]is10;a[2]is30;a.lengthis3.a[3]throws ArrayIndexOutOfBoundsException (no index 3).
Create an array with new type[size] or an initializer list {...}. Elements are indexed from 0 to length - 1, accessed as a[i]. The size is the length field (no parentheses). An index outside 0..length-1 throws an ArrayIndexOutOfBoundsException — loop with i < a.length.
配列のインデックス付けは0から始まる
a[0]=10, a[1]=20, a[2]=30; a.length は 3 です。
For int[] a = {10, 20, 30}; a[0] の値は何ですか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
配列は0からインデックスされるため、a[0] は最初の要素である10です。
配列 a のサイズをどうやって取得しますか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
配列のサイズは長サ字段(length FIELD)であり、括弧は不要です。
For int[] a = {10, 20, 30}; a.length の値は何ですか?
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
3つの要素 → length は 3 です。
長さ5の配列において、インデックス5にアクセスすると(a[5])...
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
有効なインデックスは 0..4 で、インデックス5は境界外です。
String は length()(メソッド)を使用しますが、配列は length(フィールド)を使用します。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
構文が異なります — String は括弧、配列は括弧なしです。