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.
Create and concatenate String values - Java Tutorial
From the course: Java 8+ Essential Training: Syntax and Structure
Create and concatenate String values
- [Narrator] As I've described previously, a string in Java is an instance of the string class. Here are a couple of different ways of creating them. As with all variables, you start with a type, string, and then assign a name. In Java, you can assign the value directly without creating an object first. I'll say, "This is a string." And the value has been assigned. This results in creating the string object, and assigning its initial value. Here's another version. I'll declare another string that I'll call s2, and this time I'll use object creation syntax, with new String, and I'll pass in, "This is also a string." For most purposes, these two statements are equivalent. In both cases, you're creating a string object and allocating memory. There are some subtle differences in the background that I'll describe later. As I showed in an earlier video, you can create a string from an array of characters. To create a simple array in Java, you start with the type of the objects within the…
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
-
-
-