From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,500 courses taught by industry experts.

Using string templates

Using string templates

- [Instructor] Now, the next thing I'd like to point out is that Kotlin provides us with a facility called String Templates. Because what we're doing here is really common, we're effectively concatenating three Strings together in order to print them out. Well, there's a short hand way of doing this kind of concatenation, and it looks like this. I'm just going to remove what's here. We're going to print now a single String, and that single String is going to be made up of the names. In fact, I'm going to add something else in. Let's put in the word Hello. Followed by, I want to have the Name, and then a space, and then the Surname. Now, obviously, if I print that now it's going to print Hello, Name, Surname. But using String Templates, if I put a $ in front of the name of each variable, so it's Hello, $Name, $Surname. Well, Kotlin knows that this is a shortcut way of saying, insert the value of the Name variable and insert the value of the Surname variable into my String. So, this is…

Contents