Using Java’s Type Wrappers to Convert Numeric Strings

Before leaving the topic of I/O, we will examine a technique useful when reading numeric strings. As you know, Java’s println( ) method provides a convenient way to output various types of data to the console, including numeric values of the built-in types, such as int and double. Thus, println( ) automatically converts numeric values into their human-readable form. However, methods like read( ) do not provide a parallel functionality that reads and converts a string containing a numeric value into its internal, binary format. For example, there is no version of read( ) that reads a string such as “100” and then automatically converts it into its corresponding binary value that is able to ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.