์น์์ 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]
์ถ๋ ฅ ๋จ