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 - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Declare and initialize String objects3m 45s
-
Create and concatenate String values4m 34s
-
Convert primitive values to strings5m 30s
-
Build a String from multiple values10m 35s
-
Compare String values with methods5m 19s
-
Format numeric values as strings7m 2s
-
Parse String values4m 10s
-
Challenge: A simple calculator56s
-
Solution: A simple calculator1m 26s
-
-
-