From the course: Java 11+ Essential Training

Unlock the full course today

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

Interpolate strings with placeholders

Interpolate strings with placeholders - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Interpolate strings with placeholders

- [Instructor] String interpolation is the process of evaluating a string literal containing one or more placeholders. In Java, you can do this with a method of the string class named Format. In this code, I have four different variables, three strings and one numeric value. I'm going to create a string template. I'll name it template, and I'll give it this value. I'll start with a literal string of clothing item, then for each placeholder for a string, I'll use the expression %S. You can add as many different literal strings and placeholders as you need to. I'll put the size here and the color here. You use %S for strings, but if you have numeric values, you can use %D for integers or %F for floating values. I have a floating value of 14.99 so I'll put %F here and if I want to add a dollar sign before it, I can put it right here as a literal. Now, I'll combine that template with the variable values using string format.…

Contents