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

Convert primitive values to strings - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

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