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 |
- explanation of the Second System.out.println(b+c+d+a);
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home