toUpperCase() is used to convert a string to uppercase. 1. Syntax: public String toUpperCase() 2. Return value: Returns a new string, all characters are uppercase.
Usage of toUpperCase() in Java
toUpperCase()
in Java Method used to convert all characters in a string to uppercase letters.
Syntax:
<code class="java">public String toUpperCase()</code>
Return value:
Returns a new string in which all characters are converted to uppercase letter. The original string remains unchanged.
Usage example:
<code class="java">String str = "Hello World!"; String uppercaseStr = str.toUpperCase(); System.out.println(uppercaseStr); // 输出:HELLO WORLD!</code>
Notes:
toUpperCase()
method The original string is not modified, but a new string is returned. toUpperCase()
method is the opposite of the toLowerCase()
method, which converts all characters in the string to lowercase letters. Code snippet example:
The following code snippet shows the usage of the toUpperCase()
method:
<code class="java">import java.util.Scanner; public class ToUpperCaseExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // 提示用户输入一个字符串 System.out.println("Enter a string: "); String inputString = scanner.nextLine(); // 将字符串转换为大写 String uppercaseString = inputString.toUpperCase(); // 打印出转换后的字符串 System.out.println("Uppercase string: " + uppercaseString); } }</code>
This code allows the user to enter a string, then converts it to uppercase and prints it.
The above is the detailed content of Usage of touppercase( in java. For more information, please follow other related articles on the PHP Chinese website!