Home > Java > javaTutorial > Usage of touppercase( in java

Usage of touppercase( in java

下次还敢
Release: 2024-05-08 04:45:27
Original
834 people have browsed it

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

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>
Copy after login

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>
Copy after login

Notes:

  • toUpperCase() method The original string is not modified, but a new string is returned.
  • This method only works with Unicode characters.
  • If the string does not contain any alphabetic characters, this method will return the original string. The
  • 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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template