Home > Java > javaTutorial > body text

How to use tolowercase in java

下次还敢
Release: 2024-04-26 23:48:16
Original
363 people have browsed it

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

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!