The String class is used for text manipulation. As you read, you will learn different ways to create Strings, methods to manipulate Strings, the String concatenation operator '+', and about how Strings are immutable.
10. The concat() Method
Answer:
Yes.
The parts of the statement match the documentation correctly:
String name = first.concat( last );
----+---- --+-- --+-- --+--
| | | |
| | | |
| | | +---- a String reference parameter
| | |
| | +----- the name of the method
| |
| +----- dot notation used to call an object's method.
|
+----- the method returns a reference to a new String object
The concat()
Method
concat()
MethodThe concat
method performs String
concatenation. A new String
is constructed using the data from two other String
s. In the example, the first two String
s (referenced by first
and last
) supply the data that concat()
uses to construct a third String
(referenced by name
.)
String first = "Red " ;
String last = "Rose" ;
String name = first.concat( last );
The first two String
s are NOT changed by the action of concat()
. A new String
is constructed that contains the characters "Red Rose".
The picture shows the operation of the concat()
method before the reference to the new object has been assigned to name
.
Question 10:
(Review:) Have you seenString
concatenation before?