VOOZH about

URL: https://www.geeksforgeeks.org/java/java-string-concat-examples/

⇱ Java String concat() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java String concat() Method with Examples

Last Updated : 7 Apr, 2026

The concat() method in Java is used to append one string to another and returns a new combined string. It does not modify the original string since strings are immutable.

  • Used to concatenate (join) two strings
  • Returns a new string as the result
  • Throws NullPointerException if the argument is null

Output
GeeksforGeeks

Syntax

public String concat (String s);

  • Parameters:A string to be concatenated at the end of the other string.
  • Return Value:Concatenated(combined) string.
  • Exception:NullPointerException: When either of the string is Null.

Java String concat() Examples

There are many ways to use the concat() method in Java:

Example: Combining Two Strings with concat() Method


Output
GeeksforGeeks

Example: Sequential Concatenation of Multiple Strings


Output
Computer-Science-
Computer-Science-Portal

Note: Strings are immutable in Java, so every concatenation creates a new string object instead of modifying the existing one.

Example: Handling NullPointerException in String concat()

Output

Exception in thread "main" java.lang.NullPointerException

Example: Reversing a String Using concat() Method


Output
Geeks
skeeG
Comment
Article Tags: