Home  >  Article  >  Java  >  How to use tolowercase in java

How to use tolowercase in java

下次还敢
下次还敢Original
2024-04-26 23:48:16328browse

The toLowerCase() method in Java converts the characters in the string to lowercase: returns a new string containing all lowercase characters. The original string is not changed. Affected by the locale, different locales may have different conversion rules.

How to use tolowercase in java

Detailed explanation of toLowerCase() usage in Java

Introduction
toLowerCase() Method is an instance method of the String class in Java and is used to convert all characters in the string to lowercase.

Syntax
public String toLowerCase()

Return type
Returns a new String object , which contains all lowercase characters.

Parameters
This method does not accept any parameters.

Usage
Using the toLowerCase() method is very simple, just call this method on the String object. For example:

<code class="java">String str = "Hello, World!";
String lowercaseStr = str.toLowerCase();</code>

In the above example, the value of lowercaseStr is "hello, world!".

Note

  • The toLowerCase() method does not change the content of the original string, but generates a new string.
  • The toLowerCase() method is affected by the current locale. Different locales may have different character conversion rules.
  • For immutable strings (such as String constants), you can use String.valueOf(str).toLowerCase() to get the lowercase version, since it generates a new string object.

Example

<code class="java">// 将 "JAVATPOINT" 转换为小写
String str1 = "JAVATPOINT".toLowerCase();
System.out.println(str1);  // 输出:javatpoint

// 将 "Hello, world!" 转换为小写
String str2 = "Hello, world!".toLowerCase();
System.out.println(str2);  // 输出:hello, world!</code>

The above is the detailed content of How to use tolowercase in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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