In the last tutorial, we have learned Java String's lastIndexOf() method. We have learned all the four variants of this method with an example. In this tutorial, we will learn how to convert a string into lowercase in java. We can convert all the characters of a string into lowercase by using the toLowerCase() method of Java String Class. There are two variants of the toLowerCase() method in Java. In this tutorial, we will discuss all the two variants of this method.
1. toLowerCase(): This is the first variant of toLowerCase() method of string class. This method converts all the characters of a string into lowercase. This is equivalent to calling toLowerCase(Locale.getDefault).
Syntax: The syntax of the first variant of the toLowerCase() method is given below:
Output:
2. toLowerCase(Locale locale): This is the second variant of the Java String toLowerCase() method. It converts all the characters in this String to lower case using the rule of the given locale.
Syntax: The syntax of the second variant of the toLowerCase() method is given below:
Output:
1. toLowerCase(): This is the first variant of toLowerCase() method of string class. This method converts all the characters of a string into lowercase. This is equivalent to calling toLowerCase(Locale.getDefault).
Syntax: The syntax of the first variant of the toLowerCase() method is given below:
public String toLowerCase()
Java program to convert a given string into lowercase
class toLowerCase{
public static void main(String args[]){
String str = "String Tutorial BY JavaStudyPoint";
//converting all the characters of
//a string into lowecase.
System.out.println(str.toLowerCase());
}
}
Output:
string tutorial by javastudypoint
2. toLowerCase(Locale locale): This is the second variant of the Java String toLowerCase() method. It converts all the characters in this String to lower case using the rule of the given locale.
Syntax: The syntax of the second variant of the toLowerCase() method is given below:
public String toLowerCase(Locale locale)
Java String toLowerCase(Locale locale) Method Example
import java.util.Locale;
class toLowerCase{
public static void main(String args[]){
String str = "StrIng TutorIal BY JavaStudyPoint";
//Locales with the language "tr"
//for turkish and "en" for english.
Locale turkish = Locale.forLanguageTag("tr");
Locale english = Locale.forLanguageTag("en");
//converting string str into lowercase
//using turkish and english language.
String str1 = str.toLowerCase(turkish);
String str2 = str.toLowerCase(english);
System.out.println(str1);
System.out.println(str2);
}
}
Output:
How to Convert a String into Lowercase in Java?
Reviewed by Prashant Srivastava
on
January 07, 2020
Rating:
No comments: