From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Converting primitive values to strings - Java Tutorial
From the course: Java 8 Essential Training
Converting primitive values to strings
- I've described previously how you can append primitive values to strings, for example, when you're outputting to the console. But you can also directly convert primitive values to strings using helper classes of various types. I'm working in the project, PrimitivesToStrings, where I've declared three variables: an integer, a boolean and a long. And I'll convert all three of these to strings. For the integer, I'll use a helper class. I'll declare a new string variable that I'll name fromInt, and I'll assign it using the Integer class. This class has a number of methods I could use. In addition to the simplest one, toString, there's also toBinaryString, toHexString, and toOctalString and even one named toUnsignedString. I encourage you to experiment with those, but I'll stick with the simplest one, toString. And then I'll pass in the value that I want to convert. Then I'll output the result to the console, calling System.out.println and passing in my fromInt variable. And when I run…
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
-
-
-
-
-
-
-
Working with object data types6m 27s
-
Using the String class5m 5s
-
Converting primitive values to strings4m 15s
-
Building a string from multiple values8m 44s
-
Comparing string values5m 51s
-
Formatting numeric values as strings4m 41s
-
Parsing string values3m 13s
-
Working with dates and times8m 35s
-
Challenge: Creating a simple calculator application1m 28s
-
Solution: Creating a simple calculator application1m 19s
-
-
-
-
-
-
-
-
-