--- id: java-arrays title: "Java Arrays" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["μžλ°” λ°°μ—΄"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "arrays"] raw_sources: ["https://www.w3schools.com/java/java_arrays.asp"] applied_in: [] github_commit: "" --- # [[Java Arrays]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) `new TYPE[size]` and the `{...}` literal shortcut cannot be combined (`new String[4] {"Volvo",...}` is illegal) β€” you must choose one of two modes: reserve empty slots to fill later, OR declare-and-populate at once, never both. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Declaration** β€” `String[] cars;` declares an array variable of a type with `[]`. [S1] - **Literal initialization** β€” `String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};`. [S1] - **Zero-based indexing** β€” `cars[0]` is the first element. [S1] - **Element mutation** β€” `cars[0] = "Opel";` overwrites by index. [S1] - **`.length`** β€” property (not a method call) returning element count. [S1] - **`new` keyword** β€” `new String[4]` creates an empty fixed-size array to fill later; mutually exclusive with the literal shortcut in the same declaration. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **new + literal is illegal together** β€” `new String[4] {"Volvo", "BMW", "Ford", "Mazda"}` doesn't compile; you either specify a size (`new String[4]`) OR values (`new String[] {...}` / the bare `{...}` shortcut), never both in one `new` expression. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Access: `String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; System.out.println(cars[0]); // Volvo`. [S1] - Mutation: `cars[0] = "Opel"; // Now outputs Opel instead of Volvo`. [S1] - Length: `System.out.println(cars.length); // 4`. [S1] - Empty-then-fill with new: `String[] cars = new String[4]; cars[0] = "Volvo"; ...`. [S1] - Equivalent forms: `String[] cars = new String[] {"Volvo", "BMW", "Ford", "Mazda"};` vs. the shortcut `String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};` (most common). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **new와 λ¦¬ν„°λŸ΄μ˜ 배타성**: new String[4]와 λ¦¬ν„°λŸ΄ μ΄ˆκΈ°ν™”λ₯Ό λ™μ‹œμ— μ“Έ 수 μ—†λ‹€λŠ” 점이 μ†ŒμŠ€μ—μ„œ λͺ…μ‹œμ μœΌλ‘œ 강쑰됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” μ—¬λŸ¬ 값을 ν•˜λ‚˜μ˜ λ³€μˆ˜λ‘œ κ΄€λ¦¬ν•˜λŠ” κΈ°λ³Έ 자료ꡬ쑰둜, 이후 루프/닀차원 λ°°μ—΄μ˜ 기반이 λœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Array declaration and index access (Java): ```java String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; System.out.println(cars[0]); // Volvo System.out.println(cars.length); // 4 ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[Java Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[Java For Each Loop]], [[Java Arrays Loop]], [[Java Arrays Multi]] - **μ°Έμ‘° λ§₯락:** μ—¬λŸ¬ 값을 ν•˜λ‚˜μ˜ λ³€μˆ˜λ‘œ κ΄€λ¦¬ν•˜λŠ” κΈ°λ³Έ 자료ꡬ쑰 β€” Loop/Multi μ±•ν„°λ‘œ ν™•μž₯. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” Java Arrays β€” https://www.w3schools.com/java/java_arrays.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).