Lowercase (with.Java)
In this article, we learned how to lowercase.
We’ll do this by solving a coding test problem, reflecting on the problem we solved, and learning about other ways to solve it.
Let’s start with the problem
Problem
You are given a string, myString, consisting of the alphabet.
Complete a solution function that converts all the alphabets to lowercase and returns it.
Example input and output
myString | return |
---|---|
“aBcDeFg” | “abcdefg” |
“aaa” | “aaa” |
My solution to the problem
class Solution {
public String solution(String myString) {
return myString.toLowerCase();
}
}
Solution description
String solution(String myString) : Defines a function that takes a string as input.
return myString.toLowerCase();: Returns the result of converting the string myString to lowercase.
This code converts all the characters in the input string to lowercase and returns the result. This can be useful when you don’t need to be case sensitive.