1 2 3 4 5 6 7 8 9 10 11 | public class StringConcate { public static void main(String[] args) { String s1 = "Welcome to"; String s2 = " Java"; String s3 = s1 + s2; System.out.println(s3); String s4 = s1.concat(s2); System.out.println(s4); } } |
The + operator can be used for concatenation of strings.
concat(String str) is a method of String class that concatenate two strings and return a String.