String Concatenation

String concatenation is the process where we add 2 strings to make up a new string. This can be done using the addition operator ( + ).

For instance :

String firstName = “Lahiru”;

String lastName = “Hashan”;

String name = firstName + lastName;

check out the output :

Output : LahiruHashan

No space because there is no space given.

Check out these examples :

stringconcat

Playing around with numbers :

stringconcat2

Now identify the new line and its output. Check what has happened.

stringconcat2

Now the answer has pop up without the brackets. As you can see the execution is happening from left to right. Therefore here the addition of 2 floats takes place first and then addition to the string takes place. This is an important aspect of Java.

There is a special method in String class to add strings, named “concat” method. We will be discussing in the next tutorial along with the other String methods.

See you next time.

6 thoughts on “String Concatenation

Add yours

  1. Excellent weblog right here! Additionally your site so much up very fast! What web host are you the use of? Can I am getting your affiliate hyperlink in your host? I want my site loaded up as fast as yours lol

    Liked by 1 person

  2. whoah this blog is wonderful i really like studying your articles. Keep up the good work! You know, a lot of individuals are looking round for this information, you can aid them greatly.

    Liked by 1 person

  3. I relish, cause I discovered just what I used to be having a look for. You have ended my four day lengthy hunt! God Bless you man. Have a great day. Bye

    Liked by 1 person

Leave a reply to projavasite Cancel reply

Create a free website or blog at WordPress.com.

Up ↑