programming/JAVA
[Java] 문자열을 문자열 배열로 만들기
LeeBorn
2020. 8. 31. 23:09
반응형
Java에서 문자열을 배열로 만들려면 toCharArray가 있다.
toCharArray()는 char 배열을 리턴한다.
char배열을 리턴하기 때문에 char을 다시 String으로 형변환 해줘야 할 때도 있다.
이때 split("")으로 간단하게 문자열을 문자열 배열로 만들 수 있다.
이렇게 하면 아래와 같이 출력된다.
관련해서는 아래에서 좀 더 많은 내용을 볼 수 있다.
Why in Java 8 split sometimes removes empty strings at start of result array?
Before Java 8 when we split on empty string like String[] tokens = "abc".split(""); split mechanism would split in places marked with | |a|b|c| because empty space "" exists before and after e...
stackoverflow.com
반응형