๋ณต์Šต : ๋ฐฐ์—ด ๐Ÿ˜ฎ๐Ÿ˜ฎ

๋ฆฌ๋ฌด rimu ยท2023๋…„ 3์›” 6์ผ
0

Java

๋ชฉ๋ก ๋ณด๊ธฐ
30/35

์›น์—์„œ JAVA ์ปดํŒŒ์ผ ๊ฐ€๋Šฅํ•œ ์‚ฌ์ดํŠธ
https://www.tutorialspoint.com/online_java_compiler.php

๋ฐฐ์—ด ๋ณต์Šต

public class HelloWorld {

    public static void main(String []args) {
        int[] score = new int[5];
        int count = score.length; // ๋ฐฐ์—ด์˜ ๊ธธ์ด ์–ป์„ ๋•Œ ์‚ฌ์šฉ
        System.out.println(count);
        
        score[0] = 10;
        score[1] = 20;
        score[2] = 30;
        score[3] = 40;
        score[4] = 50;
          System.out.println(score[2]);
    }
}

์ถœ๋ ฅํ•˜๋ฉด 5, 10 ๋‚˜์˜ด

๋ฐฐ์—ด ์ดˆ๊ธฐํ™”ํ•˜๋ฉด์„œ ๋ฐ”๋กœ ๊ฐ’ ์ง€์ •ํ•ด์ฃผ๋Š” ๋ฒ•

/* Online Java Compiler and Editor */
public class HelloWorld {

    public static void main(String []args) {
        int[] score = {10,20,30,40,50};
        int count = score.length; 
        System.out.println(score[score.length - 1]);
    }
}


> ์ถœ๋ ฅํ•˜๋ฉด 2 ๋‚˜์˜ด / [index๊ธธ์ด - 1 ํ˜ธ์ถœ]


String์€ ์ดˆ๊ธฐํ™”๋ฅผ ํ•ด์ฃผ์ง€์•Š์œผ๋ฉด null ์ด๋ผ๋Š” ๋ฌธ์ž์—ด์ด ๋œธ 
null = ๊ฐ’์ด ์—†๋‹ค๋Š” ๋œป



> ArrayList๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๋ฐฉ๋ฒ•

```java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class HelloWorld {

    public static void main(String[] args) {

        ArrayList <Integer> scoreList = new ArrayList<>();
        scoreList.add(10);
        scoreList.add(20);
        scoreList.add(30);
        scoreList.add(40);
        scoreList.add(50);
        
        System.out.println(scoreList.get(3));
    }
}

40 ์ด ์ถœ๋ ฅ๋œ๋‹ค!

public static void main(String[] args) {

	ArrayList <Integer> scoreList = new ArrayList<>();
    scoreList.add(10);
    scoreList.add(20);
    scoreList.add(30);
    scoreList.add(40);
    scoreList.add(50);
        
        
	scoreList.add(2,200); // 2๋ฒˆ์งธ ์ธ๋ฑ์Šค์— 200๊ฐ’ ์„ค์ • 
	System.out.println(scoreList);
	}
}

์ „์ฒด์ ์ธ ๊ฐ’์„ ํ•œ๋ฒˆ์— ๋ณผ ์ˆ˜ ์žˆ์Œ![10,20,200,30,40,50] ์ถœ๋ ฅ ๋จ

public static void main(String[] args) {

	ArrayList <Integer> scoreList = new ArrayList<>();
    scoreList.add(10);
    scoreList.add(20);
    scoreList.add(30);
    scoreList.add(40);
    scoreList.add(50);
        
        
	scoreList.add(2,200); // 2๋ฒˆ์งธ ์ธ๋ฑ์Šค์— 200๊ฐ’ ์„ค์ • 
    scoreList.remove(2) // 2๋ฒˆ์งธ ์ธ๋ฑ์Šค ๋น ์ง 
	System.out.println(scoreList);
	}
}

์ „์ฒด์ ์ธ ๊ฐ’์„ ํ•œ๋ฒˆ์— ๋ณผ ์ˆ˜ ์žˆ์Œ![10,20,30,40,50] ์ถœ๋ ฅ ๋จ

profile
JAVA / SQL / Spring ์„ ๊ณต๋ถ€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿฅ

0๊ฐœ์˜ ๋Œ“๊ธ€