public String toLowerCase(), public String toUpperCase(Locale locale)
· When you call toLowerCase(), internally toLowerCase(Locale.getDefault()) is getting called. It is locale sensitive and you should not write a logic around it interpreting locale independently.
→ toLowerCase를 사용할 때, 내부적으로는 toLowerCase(Locale.getDefault())를 사용하게 됩니다. 이 Locale은 유동적이며 Locale값을 직접 작성하지 않아도 됩니다.
→ 하지만 여기서 문제가 생기게 됩니다. 한국이나 영어와 같은 경우 소문자 변환을 하여도 크게 상관이 없지만 터키같은 국가에서는 소문자로 변경시 다르게 표시되는 글자가 있습니다.
→ English ' i '
→ Turkish ' ı '
· For instance, "TITLE".toLowerCase() in a Turkish locale returns "tıtle", where 'ı' is the LATIN SMALL LETTER DOTLESS I character. To obtain correct results for locale insensitive strings, use toLowerCase(Locale.ENGLISH).
→ 예를 들어, "TITLE".toLowerCase()를 터키언어로 리턴할 경우 "tıtle"와 같은 점이 없는 I 문자로 리턴되게 됩니다. 개발자가 의도한 대로 소문자를 변환하기 위해서는 toLowerCase(Locale.ENGLISH)로 사용해줘야 합니다.
Test Code
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class CommonTest {
public static void main(String[] args) {
String test = "iiiiiiiiiiiiiiiiiiiIIIIIIIIIIIIIIIIIII";
System.out.println(test.toLowerCase(new Locale("tr", "TR")));
}
}
Output
iiiiiiiiiiiiiiiiiiiııııııııııııııııııı
'IT > Programming' 카테고리의 다른 글
[JAVA] Quiz Server&Client - 구구단 문제 - Client (0) | 2023.04.19 |
---|---|
[JAVA] Quiz Server&Client - 구구단 문제 - Server (0) | 2023.04.19 |
<리팩토링> 소스코드 리팩토링 기본 개념, 두번째 (0) | 2023.04.19 |
<리팩토링> 소스코드 리팩토링 기본, 첫번째 (0) | 2023.04.19 |
<Code Craft> 1부 코드와 마주보기 : 01 방어하기 (2) (0) | 2023.04.19 |