From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Building a string from multiple values - Java Tutorial
From the course: Java 8 Essential Training
Building a string from multiple values
- When assembling strings, it's tempting to put them together using simple concatenation. I'm working in a project named StringBuilder, and I've declared two strings with values of Hello and World. Let's say I wanted to create a third string that put those strings together and added some extra characters. I could do this. I'll create my third string, and start with str1, and then I'll add a comma and a space, and then I'll append str2, and then I'll append an exclamation mark. And that all works fine. I'll output the value to the console and show that putting strings together like this will achieve the desired effect, but the problem is that, in order to do that, I've created three distinct objects. The original two and then the third. If you're dealing with a lot of string concatenation, this can cause problems in memory management, so, instead, it's recommended that you use a class named StringBuilder. This class is a member of the Java.lang package, so you don't need any special…
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
-
-
-
-
-
-
-
(Locked)
Working with object data types6m 27s
-
Using the String class5m 5s
-
(Locked)
Converting primitive values to strings4m 15s
-
(Locked)
Building a string from multiple values8m 44s
-
(Locked)
Comparing string values5m 51s
-
(Locked)
Formatting numeric values as strings4m 41s
-
(Locked)
Parsing string values3m 13s
-
(Locked)
Working with dates and times8m 35s
-
(Locked)
Challenge: Creating a simple calculator application1m 28s
-
(Locked)
Solution: Creating a simple calculator application1m 19s
-
(Locked)
-
-
-
-
-
-
-
-