Concat method of String in java is used to add a new String at the end of the original String.
1 |
public String concat(String str) |
String concat example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.kscodes.sampleproject; public class StringConcatExample { public static void main(String[] args) { String testStr1 = "This is test String"; String testStr2 = " Used for Concat Example."; System.out.println("After 2 String concat::" + testStr1.concat(testStr2)); System.out.println("Adding 1 more to concat::" + testStr1.concat(testStr2).concat("Added more to this String")); } } |
Output
1 2 |
After 2 String concat::This is test String Used for Concat Example. Adding 1 more to concat::This is test String Used for Concat Example.Added more to this String |
Reference
1. String API