From the course: Java 8+ Essential Training: Syntax and Structure
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 8+ Essential Training: Syntax and Structure
Convert primitive values to strings
- [Instructor] I've described previously how to append primitive values to strings, but there are some tricks to know about. To get the default representation of a primitive value, you don't need any special syntax, just append it. I'll create an integer variable that I'll name result, and I'll get its value by adding together 10 plus 12. I get 22, now I'll create a string that I'll call answer, and I'll get that value with the answer is, and then I'll append result. And I get the string, the answer is 22. So far, so good. As long as there's at least one string in a series of values, the conversion happens automatically. It doesn't matter where the string is in position. So for example, I can do this, string howMany, and I'll assign it starting with a number, and then I'll append a string. And that works fine. Because there's at least one string in the series of values, the entire thing is turned into a string. But if you try to do the same thing with a series of numbers, it won't…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Declare and initialize String objects3m 45s
-
(Locked)
Create and concatenate String values4m 34s
-
(Locked)
Convert primitive values to strings5m 30s
-
(Locked)
Build a String from multiple values10m 35s
-
(Locked)
Compare String values with methods5m 19s
-
(Locked)
Format numeric values as strings7m 2s
-
(Locked)
Parse String values4m 10s
-
(Locked)
Challenge: A simple calculator56s
-
(Locked)
Solution: A simple calculator1m 26s
-
-
-