'+' operator is used to concatenate two strings
Example One:
String myString1 = "Hey Dude ";
String myString2 = "How are you?";
String myString3 = myString1 + myString2;
Lets implement example one on Eclipse IDE:
1. Create 'StringConcatenate' class under any project as shown below:
3. Observe that the output is displayed in console as shown below:
Click here to download this project containing 'StringConcatenate' class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Example Two:
String myString1 = "Hey Dude..." + "How are you?";
Lets implement this on Eclipse IDE:
1. Create 'StringConcatenate' class under any project as shown below:
2. Save and Run the 'StringConcatenate' class file
3. Observe that the output is displayed in console as shown below:
Click here to download this project containing 'StringConcatenate' class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
How to use 'equals( )' method for comparing two strings will be explained in next post.
No comments:
Post a Comment