what is a string and how does it work?
syso(10 + 20 + “hello” + 10 + 20);
ans= 30hello1020
unable to understand.
What is a string and how does it work?
Hey @rahulkumar0116 Take into consideration the example given : syso(10 + 20 + “hello” + 10 + 20);
first as we can see 10 is int(No problem) then we see 20 is also int so added up int + int and the result should be int. Now “Hello” is a string and string datatype size(32bytes) is more than int datatype size(4 bytes) so we are adding int + string and size of string greater than int therefore overall expression becomes a string hence it becomes “30Hello”. Now we are adding 10 but String + int will be string therefore “30Hello” + 10 becomes “30Hello10” now again we are adding 20 to string therefore “30Hello10” + 20 = “30hello1020”. Remeber JVM goes from left to right.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.