Java String Concatenation Operator
- This (+) is the only overloaded operator in java.Sometimes it acts as "Arithmetic operators" and Sometimes it acts as "String Concatenation Operators".
- If both arguments are number type then it acts as "Arithmetic Addition Operator".
- If at least one argument is String type then (+)operators act as "String Concatenation Operators".
example 1:-
String a="javabychetan";
int b=10,c=20,d=30;
System.out.println(a+b+c+d); o/p is javabychetan102030
System.out.println(b+c+d+a); o/p is 60javabychetan
System.out.println(b+c+a+d); o/p is 30javabychetan30
System.out.println(b+a+c+d); o/p is 10javabychetan2030
- explanation of the first System.out.println(a+b+c+d);
javabychetan.com |