Click here to Skip to main content
15,909,437 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a doubt in Java String syntax.. Java has a function for converting characters to lower case as String.toLowerCase() which "returns a String" with lower case characters.. But if we do not assign the above method to a String variable like:

Java
String a = "aBCd";

Java
a.toLowerCase(); // Do not cause any compilation error


Correct Way

Java
a = a.toLowerCase(); // a is assigned the value of updated string


Why does the first declaration not cause any compilation error?

What I have tried:

Understanding string method in Java..
Posted
Updated 6-Feb-18 9:17am
v6

1 solution

Because you are just calling a method, which is syntactically correct in almost all computer languages. The fact that you do not save the returned value is your choice as the developer. After all, the compiler almost always assumes that you know what you are doing.
 
Share this answer
 
Comments
Maciej Los 6-Feb-18 15:34pm    
I'm not able to say it better or even shorter.
Richard MacCutchan 6-Feb-18 15:59pm    
:thumbsup: but I think you are being too kind.
Akshit Gupta 6-Feb-18 15:49pm    
Thank you sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900