From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Concatenating strings in Java

Concatenating strings in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Concatenating strings in Java

- [Instructor] So far, we've printed out the string, "Hello world," individually, and a few variables individually, but now we are going to learn how to print them together in the same line. To do this, we need to combine string values with variables that hold strings in a print statement. Using the example from the last lesson, we can print out a student's full name, and say that student has a GPA of X, with X being the student's current GPA. In the code, we'll write System.out.println, and then access the value of the student's first name, with studentFirstName. To add on the last name, we'll add a plus sign for concatenation, combining the value of these two strings. Then we'll type the variable that holds the student's last name, studentLastName. If we put the student's first and last name together like this, there will be no space between the first and last name when it is printed out to the user. We can add a space by adding a literal string, so a string that is not evaluated…

Contents