concat() method concatenates one string to the end of another string. Concatenation is the operation of joining two strings together.
Suppose we have a
str1 and another
str1.concat(str2) would return
str2 appended to the end of it.
String name = "Code"; name = name.concat("cademy"); System.out.println(name);
Codecademy would be printed.
In the code block above, we changed the value of
name by reassigning it with a new value. However,
concat() doesn’t actually change the value of the original string.
Suppose we do something slightly different:
String name = "Code"; name.concat("cademy"); System.out.println(name);
Code would be printed instead.
Store your first name in
firstName and your last name in
Print out your full name using