Java String: concat() Method
public String concat(String str)
The concat() method is used to concatenate a given string to the end of another string.
If the length of the argument string is 0, then this String object is returned.
Otherwise, a String object is returned that represents a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
Java Platform: Java SE 8
Syntax:
concat(String str)
Parameters:
Name | Description | Type |
---|---|---|
str | the String that is concatenated to the end of this String. | String |
Return Value:
a string that represents the concatenation of this object's characters followed by the string argument's characters.
greater than, equal to, or less than this String, ignoring case
considerations.
Return Value Type: string
Pictorial presentation of Java String concat() Method
Example: Java String concat() Method
public class Example {
public static void main(String[] args)
{
String str1 = "PHP Exercises and ";
String str2 = "Python Exercises";
System.out.println();
System.out.println("String 1: " + str1);
System.out.println("String 2: " + str2);
// Concatenate the two strings together.
String str3 = str1.concat(str2);
// Display the new String.
System.out.println("The concatenated string: " + str3);
System.out.println();
}
}
Output:
String 1: PHP Exercises and String 2: Python Exercises The concatenated string: PHP Exercises and Python Exercises
Java Code Editor:
Previous:compareToIgnoreCase Method
Next:contains Method
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework