java.lang.String class comes with concat() String method to concatenate two strings. The signature is given as defined in String class. public String concat(String str): Returns a new string, the result of concatenation of two strings. Following example concat() String illustrates the usage concat() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class StringMethodDemo { public static void main(String args[]) { String str1 = "Hello"; String str2 = "World"; String str3 = str1.concat(str2); System.out.println("Concatenation of " + str1 + " and " + str2 + " is " + str3); System.out.println("Concatenation of Raja and Rani is " + "Raja".concat("Rani")); System.out.println("\nUsing + operator: " + "Raja"+"Rani"); } } |
Output screenshot on concat() String…