Concatenate Strings Using String.concat()

The String class has a method called concat. It accepts as parameter a String value and concatenates it with the current String. The following code demonstrates this:

As before, this code creates string1 and string2. It then invokes the concat() method on string1 and passes string2 as an argument. So, this code also prints the same output as before:
Hello World
Performance-wise, this approach is not much better than using the + operator. Also, unlike the + operator, this approach cannot be used for multiple Strings or other types of values.

Tushar Sharma
Tushar Sharmahttps://www.automationdojos.com
Hi! This is Tushar, the author of 'Automation Dojos'. A passionate IT professional with a big appetite for learning, I enjoy technical content creation and curation. Hope you are having a good time! Don't forget to subscribe and stay in touch. Wishing you happy learning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

RELATED POSTS

Remove Duplicates from List Using HashSet

The Set is also an interface in the 'Java Collection' framework. Unlike a List, a Set does not allow duplicates. Hence you can...

Format Decimal Numbers Using Locale

If you want to create a DecimalFormat instance for a specific Locale, create a NumberFormat and cast it to a DecimalFormat. The java.text.DecimalFormat class is...

Convert List to Array Using Stream without Param

Java 8 has added the Stream API that helps to easily perform bulk operations on Collections. A new method called stream() has been added...

Â

MORE IN THIS CATEGORY

How To Load XML File into DOM Using MSXML

Microsoft XML Core Services (MSXML) provides two methods for loading XML documents into the Document Object Model (DOM) and one method and one property...

Common OpenSSH Commands Reference

Secure Shell, sometimes referred to as Secure Socket Shell (SSH), is a protocol which allows you to connect securely to a remote computer or...

Common Git Commands Reference

Git is the most popular distributed version control system which is currently an actively maintained open-source project. Git supports many command-line tools and graphical...

RECENT 'HOW-TO'

How To Install Oh-My-Posh On Windows PowerShell

Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable. It does not...

SIMILAR ON CODEX

- Advertisement -spot_img