본문 바로가기
Java

[자바] ArrayList ↔ Array 간 변환

by Sky Titan 2020. 8. 24.
728x90

1. ArrayList → Array

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {


    public static void main(String[] args) {

       ArrayList<String> list = new ArrayList<>();
       String[] array = list.toArray(new String[0]);
    }

}

 


2. Array → ArrayList

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {


    public static void main(String[] args) {

            String[] array = {"start", "finish"};
            ArrayList<String> list = new ArrayList<>(Arrays.asList(array));
    }

}

 

728x90

댓글