Examine the above. Is the following code correct?

String first = "Kublai" ;
String last  = " Khan" ;
String name  = first.concat( last );

A good answer might be:

Yes.

The concat() Method

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 performs string concatenation. This is constructing a new String by using the data in two other Strings. In the example, the first two strings (referenced by first and last) supply the data that concat uses to construct a third string (referenced by name.)

String first = "Kublai" ;
String last  = " Khan" ;
String name  = first.concat( last );

The first two Strings are NOT changed by the action of concat. A new string is constructed that contains the results of the action we wanted.

QUESTION 8:

(Review:) Have you seen string concatenation before?

Click Here after you have answered the question