logo

자바 문자열 toLowerCase()

그만큼 자바 문자열 toLowerCase() 메소드는 문자열을 소문자로 반환합니다. 즉, 문자열의 모든 문자를 소문자로 변환합니다.

toLowerCase() 메서드는 toLowerCase(Locale.getDefault()) 메서드와 동일하게 작동합니다. 내부적으로 기본 로케일을 사용합니다.


내부 구현

 public String toLowerCase(Locale locale) { if (locale == null) { throw new NullPointerException(); } int firstUpper; final int len = value.length; /* Now check if there are any characters that need to be changed. */ scan: { for (firstUpper = 0 ; firstUpper = Character.MIN_HIGH_SURROGATE) &amp;&amp; (c <= character.max_high_surrogate)) { int supplchar="codePointAt(firstUpper);" if (supplchar !="Character.toLowerCase(supplChar))" break scan; } firstupper +="Character.charCount(supplChar);" else (c firstupper++; return this; char[] result="new" char[len]; resultoffset="0;" * may grow, so i+resultoffset is the write location in just copy first few lowercase characters. system.arraycopy(value, 0, result, firstupper); string lang="locale.getLanguage();" boolean localedependent="(lang" =="tr" || 'az' 'lt'); lowerchararray; lowerchar; srcchar; srccount; for (int i="firstUpper;" <len; srcchar="(int)value[i];" ((char)srcchar>= Character.MIN_HIGH_SURROGATE &amp;&amp; (char)srcChar <= character.max_high_surrogate) { srcchar="codePointAt(i);" srccount="Character.charCount(srcChar);" } else if (localedependent || 'u03a3') greek capital letter sigma lowerchar="ConditionalSpecialCasing.toLowerCaseEx(this," i, locale); (srcchar="=" 'u0130') latin i dot ((lowerchar="=" character.error) (lowerchar>= Character.MIN_SUPPLEMENTARY_CODE_POINT)) { if (lowerChar == Character.ERROR) { if (!localeDependent &amp;&amp; srcChar == &apos;u0130&apos;) { lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(this, i, Locale.ENGLISH); } else { lowerCharArray = ConditionalSpecialCasing.toLowerCaseCharArray(this, i, locale); } } else if (srcCount == 2) { resultOffset += Character.toChars(lowerChar, result, i + resultOffset) - srcCount; continue; } else { lowerCharArray = Character.toChars(lowerChar); } /* Grow result if needed */ int mapLen = lowerCharArray.length; if (mapLen &gt; srcCount) { char[] result2 = new char[result.length + mapLen - srcCount]; System.arraycopy(result, 0, result2, 0, i + resultOffset); result = result2; } for (int x = 0; x <maplen; ++x) { result[i + resultoffset x]="lowerCharArray[x];" } - srccount); else resultoffset]="(char)lowerChar;" return new string(result, 0, len resultoffset); < pre> <h3>Signature</h3> <p>There are two variant of toLowerCase() method. The signature or syntax of string toLowerCase() method is given below:</p> <pre> public String toLowerCase() public String toLowerCase(Locale locale) </pre> <p>The second method variant of toLowerCase(), converts all the characters into lowercase using the rules of given Locale.</p> <hr> <h3>Returns</h3> <p>string in lowercase letter.</p> <hr> <h2>Java String toLowerCase() method example</h2> <pre> public class StringLowerExample{ public static void main(String args[]){ String s1=&apos;JAVATPOINT HELLO stRIng&apos;; String s1lower=s1.toLowerCase(); System.out.println(s1lower); }} </pre> <span> Test it Now </span> <p>Output:</p> <pre> javatpoint hello string </pre> <h2>Java String toLowerCase(Locale locale) Method Example 2</h2> <p>This method allows us to pass locale too for the various langauges. Let&apos;s see an example below where we are getting string in english and turkish both.</p> <pre> import java.util.Locale; public class StringLowerExample2 { public static void main(String[] args) { String s = &apos;JAVATPOINT HELLO stRIng&apos;; String eng = s.toLowerCase(Locale.ENGLISH); System.out.println(eng); String turkish = s.toLowerCase(Locale.forLanguageTag(&apos;tr&apos;)); // It shows i without dot System.out.println(turkish); } } </pre> <p>Output:</p> <pre> javatpoint hello string javatpo?nt hello str?ng </pre></maplen;></=></=>

toLowerCase()의 두 번째 메소드 변형은 주어진 Locale의 규칙을 사용하여 모든 문자를 소문자로 변환합니다.


보고

소문자로 된 문자열입니다.


Java 문자열 toLowerCase() 메소드 예

 public class StringLowerExample{ public static void main(String args[]){ String s1=&apos;JAVATPOINT HELLO stRIng&apos;; String s1lower=s1.toLowerCase(); System.out.println(s1lower); }} 
지금 테스트해보세요

산출:

 javatpoint hello string 

Java 문자열 toLowerCase(Locale locale) 방법 예 2

이 방법을 사용하면 다양한 언어에 대한 로캘도 전달할 수 있습니다. 아래에서 영어와 터키어로 문자열을 얻는 예를 살펴보겠습니다.

 import java.util.Locale; public class StringLowerExample2 { public static void main(String[] args) { String s = &apos;JAVATPOINT HELLO stRIng&apos;; String eng = s.toLowerCase(Locale.ENGLISH); System.out.println(eng); String turkish = s.toLowerCase(Locale.forLanguageTag(&apos;tr&apos;)); // It shows i without dot System.out.println(turkish); } } 

산출:

 javatpoint hello string javatpo?nt hello str?ng