Combining Strings with String Concatenation in Java

06 May 2023 Balmiki Mandal 0 Core Java

What is String Concatenation?

String concatenation is the process of combining two or more strings together to form a single string. In Java, you can use the + operator to concatenate two strings together.

How To Use String Concatenation in Java?

Using string concatenation with the + operator is relatively simple. All you need to do is place two strings together, with the + symbol in between. For example:

String str1 = "Hello";
String str2 = "World";
String str = str1 + str2;
System.out.println(str); //outputs "Hello World"

If you want to add more than two strings together, you can use the same method, but just keep adding strings. For example:

String str1 = "Hello";
String str2 = "World";
String str3 = "!";
String str = str1 + str2 + str3;
System.out.println(str); //outputs "Hello World!"

Conclusion

String Concatenation is a very useful tool in Java and is a great way to combine multiple strings together into one. With just a few lines of code, you can quickly and easily combine two or more strings together.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.