From 189423e97d0faf89cb9f8ce89a0653733174302b Mon Sep 17 00:00:00 2001 From: bin <119281411+kyubiin@users.noreply.github.com> Date: Thu, 6 Jul 2023 12:21:54 +0900 Subject: [PATCH] =?UTF-8?q?8.=20=EC=9E=90=EB=A3=8C=EA=B5=AC=EC=A1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 배열 / 리스트 / 맵 --- ArraysExample.java | 26 ++++++++++++++++++++++++++ ListsExample.java | 22 ++++++++++++++++++++++ MapsExample.java | 19 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 ArraysExample.java create mode 100644 ListsExample.java create mode 100644 MapsExample.java diff --git a/ArraysExample.java b/ArraysExample.java new file mode 100644 index 0000000..60a925a --- /dev/null +++ b/ArraysExample.java @@ -0,0 +1,26 @@ +import java.sql.SQLOutput; + +public class ArraysExample { + + public static void main(String[] args) { + + // 배열(Arrays) + + int[] price = {10000, 9000, 40000, 7000}; + String[] mbti = {"INFP", "ENFP", "ISTJ", "ESTP"}; + + System.out.println(mbti.length); + + for(int i = 0; i < mbti.length ; i++){ + System.out.println(mbti[i]); + } + +// System.out.println(price[0]); +// System.out.println(mbti[0]); +// +// price[1] = 8000; +// System.out.println(price[1]); +// +// System.out.println(price); + } +} diff --git a/ListsExample.java b/ListsExample.java new file mode 100644 index 0000000..9481f53 --- /dev/null +++ b/ListsExample.java @@ -0,0 +1,22 @@ +import java.util.ArrayList; + +public class ListsExample { + + public static void main(String[] args) { + + // Lists + // 순서 구분, 중복 허용 + // Vector, ArrayList, LinkedList + + ArrayList list = new ArrayList(10); + list.add(100); + list.add("INFP"); + // ArrayList의 자료형을 명시하지 않은 경우 여러 자료형을 입력 가능 + + ArrayList list_A = new ArrayList<>(10); // 자료형 명시할 경우 객체타입 작성 + + for(int i = 0; i < list.size(); i++){ + System.out.println(list.get(i)); + } + } +} diff --git a/MapsExample.java b/MapsExample.java new file mode 100644 index 0000000..8e45bf1 --- /dev/null +++ b/MapsExample.java @@ -0,0 +1,19 @@ +import java.util.HashMap; + +public class MapsExample { + + public static void main(String[] args) { + + // Map + // 키-값 쌍을 요소로 가지는 데이터의 모음, 순서 구분 없음 + // 키는 중복 불가, 값은 중복 허용 + + HashMap map = new HashMap(); + map.put("age", 30); + map.put("mbti", "INFP"); + + System.out.println(map.get("age")); + + HashMap map_A = new HashMap<>(); // 자료형 명시한 경우 + } +}