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

Create and concatenate String values - Java Tutorial

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

Start my 1-month free trial

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…

Contents