Java String concat() method example

HQ » Java Tutorial » java.lang » String » concat() method example
Java String concat() method example 2018-02-19T12:40:46+00:00

java.lang.String concat()

Description :

This java tutorial shows how to use the concat() method of java.lang.String class. This method returns a new String object which is the result of combining the String object to the method argument String. This method is simply a shortcut in doing the following expression

“this string”+”another string”.

Method Syntax :

public String concat(String str)

Parameter Input :

DataType Parameter Description
String str the string to be combined as a suffix(at the end) to our String object

Method Returns :

This method returns a new String object which is the result of combining our String to that of the String method argument.

Compatibility Version :

Since the beginning

Exception :


Java Code Example :

This example source code demonstrates the use of concat() method of String class. Basically this source code just prints the concatenated String of our parent String and our input String object.

For this example, we will be showing a practical scenario. First and foremost we will be reading our console for the student first name and last name. The Scanner class will be very useful on this scenario to read the console input from the user. We will be using the concat() method to get the full name by combining the first name and last name. This is an ideal practical scenario to demonstrate the use of this useful string method.

Sample Output :

Running the concat() method example source code of java.lang.String class will give you the following output

concat method example

String concat method example output

Suggested Reading List :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.