Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

10. Numbers and Statics: Numbers Matter > But wait! There’s more! Wrappers have...

But wait! There’s more! Wrappers have static utility methods too!

Besides acting like a normal class, the wrappers have a bunch of really useful static methods. We’ve used one in this book before—Integer.parseInt().

The parse methods take a String and give you back a primitive value.

Converting a String to a primitive value is easy:

image with no caption

But if you try to do this:

image with no caption

You’ll get a runtime exception:

image with no caption

Every method or constructor that parses a String can throw a NumberFormatException. It’s a runtime exception, so you don’t have to handle or declare it. But you might want to.

(We’ll talk about Exceptions in the next chapter.)


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial