📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this guide, you will learn about the Character toLowerCase() method in Java programming and how to use it with an example.
1. Character toLowerCase() Method Overview
Definition:
The toLowerCase() method from the Java Character class converts the character argument to lowercase using case mapping information from the Unicode data file. It does not take into account the locale of the user.
Syntax:
1. static char toLowerCase(char ch)
2. static int toLowerCase(int codePoint)
Parameters:
char ch: The character to be converted.
int codePoint: The character (Unicode code point) to be converted.
Key Points:
- The method is useful for converting individual characters, not entire strings. For converting strings, it's recommended to use String.toLowerCase().
- The method will return the same character if it is already in lowercase or if it doesn't have a lowercase equivalent.
- The conversion is based on the Unicode standard and doesn't take the locale into account. This means the conversion might not be appropriate for all linguistic contexts.
2. Character toLowerCase() Method Example
public class ToLowerCaseExample {
public static void main(String[] args) {
char testChar1 = 'A';
char testChar2 = 'a';
int testCodePoint = 0x0130; // Latin Capital Letter I With Dot Above
System.out.println("Lowercase of '" + testChar1 + "' is: " + Character.toLowerCase(testChar1));
System.out.println("Lowercase of '" + testChar2 + "' is: " + Character.toLowerCase(testChar2));
System.out.println("Lowercase of Latin Capital Letter I With Dot Above is: " + (char)Character.toLowerCase(testCodePoint));
}
}
Output:
Lowercase of 'A' is: a Lowercase of 'a' is: a Lowercase of Latin Capital Letter I With Dot Above is: i
Explanation:
In the example, the toLowerCase() method is applied to an uppercase letter 'A', a lowercase letter 'a', and a Unicode character 'Latin Capital Letter I With Dot Above'.
For 'A', the function converts and returns the lowercase 'a'.
For the already lowercase 'a', it simply returns 'a' again.
For the 'Latin Capital Letter I With Dot Above', the function converts and returns the lowercase 'i'.
Comments
Post a Comment
Leave Comment