๐ List
: ๋ฐฐ์ด๊ณผ ๋์ผ -> ์ธํฐํ์ด์ค
- ๊ฐ์ ํ๋์ฉ ์ ์ฅ
- ์์๋ฅผ ๋ณด์ฅ
- ์ค๋ณต์ ํ์ฉ
- ๋ฎ์ด์ฐ๊ธฐx = ๋ฃ์ผ๋ฉด ๊ฐ์ฅ ๋ค์ ์ถ๊ฐ
- ๋ฐฐ์ด ๋์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ
//์ซ์๋ง ๊ฐ๋ฅํ ArrayList ์์ฑ
ArrayList<Integer> list = new ArrayList<Integer>();
//๋ฌธ์์ด๋ง ๊ฐ๋ฅํ ArrayList ์์ฑ
ArrayList<String> list3 = new ArrayList<String>();
//add() : ์์๋ฅผ ์ถ๊ฐ
list.add(1);
list.add(2);
list.add(3);
System.out.println(list);
System.out.println(list.toString());
//size() : list์ ์ด ๊ฐ์
System.out.println(list.size() + "๊ฐ");
//get(index) : index๋ฒ์ง์ ๊ฐ์ ๊ฐ์ ธ์ค๊ธฐ
System.out.println(list5.get(1));
//set(index,๊ฐ) : index๋ฒ์ง์ ๊ฐ์ ๋ฃ์ด ๋ฐ๊พธ์ธ์(๋ณ๊ฒฝ)
System.out.println(list.set(2, 0));
System.out.println(list.get(2));
// list์ ๊ฐ ์ญ์ ํ๊ธฐ
//1) remove(index) : index ๋ฒ์ง ๊ฐ ์ญ์
list5.remove(1); //1๋ฒ์ง ์ญ์
System.out.println(list5);
//2) remove(object) : object ๊ฐ์ผ๋ก ๋ฃ์ผ๋ฉด ๊ฐ์ผ๋ก ์ญ์
Integer a =10;
list5.remove(a);
System.out.println(list5);
//contains(Object) : list์ ๊ฐ์ด ์๋์ง ๊ฒ์ฌ => ์๋๊ฒฝ์ฐ true, ์๋ ๊ฒฝ์ฐ false
System.out.println(list5.contains(a));
//clear() : list์ญ์
list5.clear();
System.out.println(list5);
//isEmpty() : list๊ฐ ๋น์ด์๋์ง ํ์ธ => ๋น์ด์๋ ๊ฒฝ์ฐ true
System.out.println(list.isEmpty());
//indexOf(๊ฐ) : ํด๋น ๊ฐ์ list index๋ฒ์ง๋ฅผ ๋ฐํ / ์๋ค๋ฉด -1๋ฆฌํด
System.out.println();
System.out.println("indexOf > ");
Integer b = 5;
System.out.println(list5.indexOf(b));
'JAVA > java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ์ปฌ๋ ์ ํ๋ ์์ํฌ : Map (์์X, key์ค๋ณตX/Value์ค๋ณตO) (0) | 2023.03.26 |
---|---|
[JAVA] ์ปฌ๋ ์ ํ๋ ์์ํฌ : Set (์ค๋ณตX, ์์X) (0) | 2023.03.26 |
[JAVA] ์ปฌ๋ ์ ํ๋ ์์ํฌ (List, Set, Map) (0) | 2023.03.26 |
[JAVA] ์ ์บ์คํ / ๋ค์ด์บ์คํ (0) | 2023.03.26 |
[JAVA] ๋คํ์ฑ (๊ฐ์ฒด์งํฅํ๋ก๊ทธ๋จ ํน์ง) (0) | 2023.03.26 |