logo

Chaîne Java versUpperCase()

Le chaîne java versUpperCase() La méthode renvoie la chaîne en majuscule. En d’autres termes, il convertit tous les caractères de la chaîne en lettres majuscules.

La méthode toUpperCase() fonctionne de la même manière que la méthode toUpperCase(Locale.getDefault()). Il utilise en interne les paramètres régionaux par défaut.


Implémentation interne

 public String toUpperCase(Locale locale) { if (locale == null) { throw new NullPointerException(); } int firstLower; final int len = value.length; /* Now check if there are any characters that need to be changed. */ scan: { for (firstLower = 0 ; firstLower = Character.MIN_HIGH_SURROGATE) &amp;&amp; (c <= character.max_high_surrogate)) { c="codePointAt(firstLower);" srccount="Character.charCount(c);" } else int uppercasechar="Character.toUpperCaseEx(c);" if ((uppercasechar="=" character.error) || (c !="upperCaseChar))" break scan; firstlower +="srcCount;" return this; char[] result="new" char[len]; * may grow resultoffset="0;" grow, so i+resultoffset is the write location in just copy first few uppercase characters. system.arraycopy(value, 0, result, firstlower); string lang="locale.getLanguage();" boolean localedependent="(lang" =="tr" 'az' 'lt'); upperchararray; upperchar; srcchar; srccount; for (int i="firstLower;" <len; srcchar="(int)value[i];" ((char)srcchar>= Character.MIN_HIGH_SURROGATE &amp;&amp; (char)srcChar = Character.MIN_SUPPLEMENTARY_CODE_POINT)) { if (upperChar == Character.ERROR) { if (localeDependent) { upperCharArray = ConditionalSpecialCasing.toUpperCaseCharArray(this, i, locale); } else { upperCharArray = Character.toUpperCaseCharArray(srcChar); } } else if (srcCount == 2) { resultOffset += Character.toChars(upperChar, result, i + resultOffset) - srcCount; continue; } else { upperCharArray = Character.toChars(upperChar); } /* Grow result if needed */ int mapLen = upperCharArray.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]="upperCharArray[x];" } - srccount); else resultoffset]="(char)upperChar;" return new string(result, 0, len resultoffset); < pre> <hr> <h3>Signature</h3> <p>There are two variant of toUpperCase() method. The signature or syntax of string toUpperCase() method is given below:</p> <pre> public String toUpperCase() public String toUpperCase(Locale locale) </pre> <p>The second method variant of toUpperCase(), converts all the characters into uppercase using the rules of given Locale.</p> <hr> <h3>Returns</h3> <p>string in uppercase letter.</p> <hr> <h2>Java String toUpperCase() method example</h2> <pre> public class StringUpperExample{ public static void main(String args[]){ String s1=&apos;hello string&apos;; String s1upper=s1.toUpperCase(); System.out.println(s1upper); }} </pre> <span> Test it Now </span> <p>Output:</p> <pre> HELLO STRING </pre> <h2>Java String toUpperCase(Locale locale) Method Example 2</h2> <pre> import java.util.Locale; public class StringUpperExample2 { public static void main(String[] args) { String s = &apos;hello string&apos;; String turkish = s.toUpperCase(Locale.forLanguageTag(&apos;tr&apos;)); String english = s.toUpperCase(Locale.forLanguageTag(&apos;en&apos;)); System.out.println(turkish);//will print I with dot on upper side System.out.println(english); } }</pre> <p>Output:</p> <pre> HELLO STR?NG HELLO STRING </pre></maplen;></=>

La deuxième variante de méthode de toUpperCase() convertit tous les caractères en majuscules en utilisant les règles de la localisation donnée.

méthode remplaçant en java

Retour

chaîne en lettre majuscule.


Exemple de méthode Java String toUpperCase()

 public class StringUpperExample{ public static void main(String args[]){ String s1=&apos;hello string&apos;; String s1upper=s1.toUpperCase(); System.out.println(s1upper); }} 
Testez-le maintenant

Sortir:

 HELLO STRING 

Méthode Java String toUpperCase (Locale locale) Exemple 2

 import java.util.Locale; public class StringUpperExample2 { public static void main(String[] args) { String s = &apos;hello string&apos;; String turkish = s.toUpperCase(Locale.forLanguageTag(&apos;tr&apos;)); String english = s.toUpperCase(Locale.forLanguageTag(&apos;en&apos;)); System.out.println(turkish);//will print I with dot on upper side System.out.println(english); } }

Sortir:

cacahuète contre arachide
 HELLO STR?NG HELLO STRING