The Java String concat() method concatenates one string to the end of another string.This method returns a string with the value of the string passed into the method, appended to the end of the string.
Signature:
public String concat(String anostr)
Parameter:
anostr- string to be concatenated at the end of the another string.
Return:
combination of two strings are returned.
Example:To show working of concat() method
// Java program to demonstrate // working of concat() method class Gfg { public static void main(String args[]) { String s = "Gfg"; s = s.concat("! is the best."); System.out.println(s); } } |
chevron_right
filter_none
Output:
Gfg! is the best.
// Java program to demonstrate // working of concat() method class Gfg { public static void main(String args[]) { String s = "Gfg"; // We must explicitly assign result // of s.concat() to s. Since not // assigned to s, s does not change. s.concat("! is the best."); System.out.println(s); } } |
chevron_right
filter_none
Output:
Gfg
Recommended Posts:
- DoubleStream concat() in Java
- IntStream concat() in Java
- LongStream concat() in Java
- Stream.concat() in Java
- Ints concat() function | Guava | Java
- Java String format() with examples
- Java String toLowerCase() with examples
- Java String endsWith() with examples
- Java String getChars() with examples
- Java String join() with examples
- String toString() Method in java with Examples
- Split() String method in Java with examples
- Java String subSequence() method with Examples
- ZoneOffset of(String) method in Java with Examples
- Matcher replaceAll(String) method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



