ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

concat() method of String class in Java

In Java, there are two ways to concatenate two strings. You can use the concat method or the plus “+” character. Sun developers are using plus operator inside the body of concat method. concat method is used for achieving more readability.

The method return type is a String with the value of the String passed in to the method appended to the end of the String used to invoke this method.

Syntax:

  1. public String concat(String temp);

Let us take an example to understand this method in deep :

  1. public class DemoConcat{
  2.  
  3. public static void main(String args[]) {
  4.  
  5. String s = "Strings are easy";
  6.  
  7. s = s.concat(" to learn");
  8.  
  9. System.out.println(s);
  10.  
  11. }
  12.  
  13. }

OUTPUT:

Strings are easy to learn

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!