From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

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

Build a String from multiple values

Build a String from multiple values - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Build a String from multiple values

- [Host] As I described previously, a string object in Java is immutable. Its value can't be changed. When you append or replace a string's value, you're really discarding the existing object and creating a new one in memory. To create a complex string from scratch, without leaving a trail of temporary string objects in your wake, you can use a class named StringBuilder. Now this code gets a little bit more complex than what we've been doing so far, so I'm going to move from JShell into an IntelliJ IDEA project, and I'm going to put the code into an actual Java class. From the welcome screen, I'll create a new project. I'll accept the Java type and my Project SDK of 9.0. I'll create a new project from the template Command Line App. I'll change the project name to StringBuilder, and I'll place it in the appropriate chapter and folder for this video. That's Chapter 4, 04, 04. If you're following along, just make sure you've set your base package to com.example.java. Now click finish…

Contents