Java String.concat() Method

Java String.concat() Method

By Yashwant Chavan, Views 1791, Date 16-Nov-2016

In this tutorial you will learn how to concatenate strings using String .concat() method in Java. Each time it will creates new String in String constant pool.

tags java

Refer below steps

  • String.concat(String str) method concatenates the specified string to the end of this string.
  • Parameters: str the String which you want to concatenated to the end of this String.
  • It throws NullPointerException if you pass null value to concat() method. Refer second scenario

Java String.concat() method example


public class StringConcat {

    public static void main(String args[]) {
        String str = "hello";
        str = str.concat(" world!!");


        String hello = "hello";
        hello = hello.concat(null);



hello world!!
Exception in thread "main" java.lang.NullPointerException
 at java.lang.String.concat(

Suggested Posts



Hi there! I am founder of and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][]