Given a string s
, return the string after replacing every uppercase letter with the same lowercase letter.
Java provides built-in methods to convert a string to lowercase, making this problem straightforward to solve using the toLowerCase
method of the String
class.
public class Solution {
public String toLowerCase(String s) {
return s.toLowerCase();
}
public static void main(String[] args) {
Solution solution = new Solution();
// Test Cases
System.out.println(solution.toLowerCase("Hello")); // Output: "hello"
System.out.println(solution.toLowerCase("here")); // Output: "here"
System.out.println(solution.toLowerCase("LOVELY")); // Output: "lovely"
}
}
Using the toLowerCase
method leverages Java’s highly optimized internal libraries for character conversion, providing a concise and efficient solution.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?