Welcome to My World (www.dgmayor.com)

소프트웨어 (과거)/자바 GUI & C# 등...

12. arrayList 사용법

dgmayor 2022. 2. 15. 16:30
728x90

ArrayList 요소 출력

import java.util.ArrayList;
public class Main {
 public static void main(String[] args) {
  ArrayList<String> arrayList = new ArrayList<String>();
  arrayList.add("1");
  arrayList.add("2");
  arrayList.add("3");
  arrayList.add("SniperM");
  /*
   * for (int i = 0; i < arrayList.size(); i++) {
   * System.out.println(arrayList.get(i)); }
   */
  int totalElements = arrayList.size();// arrayList의 요소의 갯수를 구한다.
  for (int index = 0; index < totalElements; index++) {
   System.out.println(arrayList.get(index));
  }

 }
} 

 

이게 뭐라고 업로드 하는가 하는데......

문법 하나 때문에 잡아 먹는 시간이 적지 않다...

기존 배열과의 차이점은.... 어레이 리스트 사용시 배열의 크기를 신경 쓰지 않아도 되는 것이다.

 

더 큰 팁은.....


public static ArrayList<String> Order = new ArrayList<String>();

public static ArrayList<String[]> Detail = new ArrayList<String[]>();

Detail.add(new String[]{"아메리카노", "0", "0", "0", "0", "0"});

이건 나중에 추가한건데...... 확실히 실력이 느는게 느껴진다.

728x90