In: Computer Science
What is s after the following? String s = "AbCd"; s.toLowerCase(); |
|||||||||
|
The function toLowerCase() is used to convert all the letters in a given string to lowercase letters without affecting the length of the string.
For the given question:
String s = "AbCd"; s.toLowerCase();
As we mentioned that this function will simply convert all the letters into lowercase but this given program is not complete. Therefore, there are two possibilities for the output:
Case 1: In the first case, if we consider the same code as given and just print the string 's' as output in the 3rd like then we will get the same string which was initialised (which is "AbCd"). This is happening because we are not storing the result. Hence, no changes are made to the initialised string even after calling the function.
Case 2: In this case which is most likely to be implemented, we consider the new variable to store the value and then print it or we can store the value in the same string variable, and then the old value will be replaced by the new one. This can be written as
String s = "AbCd";
s = s.toLowerCase();
After printing the s, we will get "abcd" as the output and that's the output we get through the toLowerCase() function.
In Short,
String s = "AbCd";
s.toLowerCase();
OUTPUT: s = "AbCd"
String s = "AbCd";
s = s.toLowerCase();
OUTPUT: s = "abcd"
If you liked my answer, then please give me a thumbs up.