DEV Community


String important points

anandsingh8 profile image Anand Singh ・1 min read

String s1="java";
String s2="coder";

//Sop means System.out.println(for print)

Sop(s1+s2); //output-javacoder

Sop(s1+10); // java10
//10 is treated like a string.

Sop(s1+10+20); //java1020

Sop(10+20+s1); //30java
//First 10 and 20 were added and then 30 concat with s1.

note-Left to right operation takes place with the plus operator ... first addition will happen and then concat.

Sop(10+s1+20); //10java20

Sop(s1+20/10); //java2
//First division took place and then concat method was used

Note--BODMAS rule is used in Java ... if you do not know the bodmas rule then do a Google search.

Sop(s1+10-5); //error

//first s1+10 =java10
then java10-5
java10 -5 is not possible, so we will get error.

If you found this post useful, then follow me❤️

Discussion (1)

Editor guide
peledzohar profile image
Zohar Peled • Edited

At first I thought to myself - Well, maybe Java's compiler is that dumb, no way C# will allow this! I had to try...

Implicit conversions