The Optimum Method to Concatenate Strings in Java.


The Optimum Method to Concatenate Strings in Java is the concat() method.

This method appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.

Example

Live Demo

public class Test {
   public static void main(String args[]) {
      String s = "Strings are immutable";
      s = s.concat(" all the time");
      System.out.println(s);
   }
} 

Output

Strings are immutable all the time

Updated on: 26-Feb-2020

125 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements