"자바 String 숫자를 자릿수 int 배열로 분할"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 5개는 보이지 않습니다)
2번째 줄: 2번째 줄:
;자바 String 숫자를 자릿수별 int 배열로 분할
;자바 String 숫자를 자릿수별 int 배열로 분할


<source lang='java'>
<syntaxhighlight lang='java' run>
import java.util.Arrays;
import java.util.Arrays;
import java.util.stream.Stream;  
import java.util.stream.Stream;
public class MyClass {
 
public class App {
     public static void main(String args[]) {
     public static void main(String args[]) {
         String str = "12345";
         String str = "12345";
         int[] digits = Stream.of(str.split("")).mapToInt(Integer::parseInt).toArray();
         int[] digits = Stream.of(str.split("")).mapToInt(Integer::parseInt).toArray();
         System.out.println( Arrays.toString(digits) );
         System.out.println(Arrays.toString(digits));
        // [1, 2, 3, 4, 5]
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java' run>
import java.util.Arrays;
import java.util.Arrays;
public class MyClass {
 
public class App {
     public static void main(String args[]) {
     public static void main(String args[]) {
         String str = "12345";
         String str = "12345";
         int[] digits = new int[str.length()];
         int[] digits = new int[str.length()];
         for(int i=0; i<str.length(); i++) digits[i] = str.charAt(i) - '0';
         for (int i = 0; i < str.length(); i++)
         System.out.println( Arrays.toString(digits) );
            digits[i] = str.charAt(i) - '0';
        // [1, 2, 3, 4, 5]
         System.out.println(Arrays.toString(digits));
     }
     }
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[자릿수]]
* [[자바 int 배열을 String으로 변환]]
* [[자바 int 배열을 String으로 변환]]
* [[자바 int를 자릿수 int 배열로 분할]]
* [[자바 int를 자릿수 int 배열로 분할]]
33번째 줄: 35번째 줄:
* [[자바 String을 char 배열로 변환]]
* [[자바 String을 char 배열로 변환]]
* [[String 숫자를 자릿수별 int 배열로 분할]]
* [[String 숫자를 자릿수별 int 배열로 분할]]
* [[자릿수]]


==참고==
==참고==

2022년 12월 25일 (일) 00:53 기준 최신판

1 개요[ | ]

자바 String 숫자를 자릿수별 int 배열로 분할
import java.util.Arrays;
import java.util.stream.Stream;

public class App {
    public static void main(String args[]) {
        String str = "12345";
        int[] digits = Stream.of(str.split("")).mapToInt(Integer::parseInt).toArray();
        System.out.println(Arrays.toString(digits));
    }
}
import java.util.Arrays;

public class App {
    public static void main(String args[]) {
        String str = "12345";
        int[] digits = new int[str.length()];
        for (int i = 0; i < str.length(); i++)
            digits[i] = str.charAt(i) - '0';
        System.out.println(Arrays.toString(digits));
    }
}

2 같이 보기[ | ]

3 참고[ | ]