Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Java Program to Concatenate String



The concat() method of the String class concatenates the specified string to the end of this string.

Example

Live Demo

import java.lang.*;
   public class StringDemo {
      public static void main(String[] args) {

      // print str1
      String str1 = "self";
      System.out.println(str1);

      // print str2 concatenated with str1
      String str2 = str1.concat(" learning");
      System.out.println(str2);

      // prints str3 concatenated with str2(and str1)
      String str3 = str2.concat(" center");
      System.out.println(str3);
   }
}

Output

self
self learning
self learning center
Updated on: 2020-02-26T05:59:28+05:30

337 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements