Concat() Method of String class in Java

0
9

This tutorial is all about 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

Readers might read this also:

Thread States / Thread Life Cycle in Java

Scanner Class in Java

Regular Expressions

 

 

 

 

Facebook Comments
(Visited 8 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here