한 걸음 두 걸음

String 단어 한개씩 쪼개기 본문

Language/Java

String 단어 한개씩 쪼개기

언제나 변함없이 2020. 1. 22. 14:24
반응형

1. 1차배열 / toCharArray

package day0122;
import java.util.Arrays;
public class Solution {

    public static void main(String[] args) {
        String str = "abcdefg";
        char[] arr = new char[5];
        arr = str.toCharArray();
        System.out.println(Arrays.toString(arr)+"");

        //2차배열 / toCharArray
        char[][] arr1 = new char[5][];
        arr1[0] = str.toCharArray();
        System.out.println(Arrays.toString(arr1[0])+"");

        //string[]
        String[] test = new String[100];
        test = str.split("");
        System.out.println(Arrays.toString(test));



    }
}

2. 2차배열 / toCharArray

package day0122;
import java.util.Arrays;
public class Solution {

    public static void main(String[] args) {
        String str = "abcdefg";

        //2차배열 / toCharArray
        char[][] arr1 = new char[5][];
        arr1[0] = str.toCharArray();
        System.out.println(Arrays.toString(arr1[0])+"");
    }
}

3. String 배열

package day0122;
import java.util.Arrays;
public class Solution {

    public static void main(String[] args) {
        //string[]
        String[] test = new String[100];
        test = str.split("");
        System.out.println(Arrays.toString(test));



    }
}
반응형