From the course: Java 11+ Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Convert primitive values to strings - Java Tutorial
From the course: Java 11+ Essential Training
Convert primitive values to strings
I've described previously how to append primitive values to strings. To get the default representation of a primitive value you don't need any special syntax, you just append it using the plus operator as shown here. I am now working in a branch of my GitHub repository, that's designed as a starting branch. As always you can go to the ending version of this exercise any time you like. I'll run this code, and see the output. As long as there's at least one string in a series of values, this sort of conversion happens correctly. I'll create a new string and I'll use explicit typing, I'll name the string howMany, and I'll give it a value of 20, and then I'll append a string of things, and then I'll output that variable, and I get 20 things. But here's what happens if you try to append two numbers in the same way. If you use explicit typing, I'll name this result2 and I'll add 10 plus 20, and if I move the cursor over…
Contents
-
-
-
-
-
-
(Locked)
Declare and initialize string values3m 55s
-
(Locked)
Build a string from multiple values4m
-
(Locked)
Clone the exercise files from GitHub3m 57s
-
(Locked)
Convert primitive values to strings3m 29s
-
(Locked)
Format numeric values as strings5m 55s
-
(Locked)
Interpolate strings with placeholders3m 7s
-
(Locked)
Compare string values4m 27s
-
(Locked)
Parse string values2m 36s
-
(Locked)
Get string values from user input3m 34s
-
(Locked)
Challenge: A simple calculator1m 9s
-
(Locked)
Solution: A simple calculator1m 18s
-
(Locked)
-
-
-
-
-
-