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 - Java Tutorial
From the course: Java 11+ Essential Training
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
-
-
-
-
-
-
Declare and initialize string values3m 55s
-
Build a string from multiple values4m
-
Clone the exercise files from GitHub3m 57s
-
Convert primitive values to strings3m 29s
-
Format numeric values as strings5m 55s
-
Interpolate strings with placeholders3m 7s
-
Compare string values4m 27s
-
Parse string values2m 36s
-
Get string values from user input3m 34s
-
Challenge: A simple calculator1m 9s
-
Solution: A simple calculator1m 18s
-
-
-
-
-
-
-