Home : Course Map : Chapter 3 : Java : Tech :
More about Number Wrappers
JavaTech
Course Map
Chapter 3

Introduction
Class Definition
Data Fields
Methods
Constructors
Instantiation
  
Demo 1
  Demo 2
Static Members
  Demo 3

Value&Reference
  Demo 4
Overloading
   Demo 5
Wrappers 
  Demo 6
Autobox/Unbox
   Demo 7
Arrays
  Demo 8
Exceptions
Exercises

    Supplements
MoreAboutObjects
Creating Types

Classes,Objs&JVM

Java OOP vs C++
Garbage Collection
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New
As we discussed in the Java track, the primitive type number wrapper classes offer many useful features. They also illustrate how classes can offer static methods for general use and can also be instantiated.

In technical programs you often need to convert back and forth from numbers and strings. The following table offers a quick reference to find the static method to use in the number wrappers for a given conversion. (Here radix refers to the base for the number format.)

Number - String Conversion Tools
Wrapper Primitive to String String to Primitive
Byte Byte.toString(byte b) Byte.parseByte(String s)
Byte.parseByte(String s,
   int radix)
Short Short.toString(short s) Short.parseShort(String s)
Short.parseShort(String s,
   int radix)
Integer Integer.toString(int i) Integer.parseInt(String s)
Integer.toString(int i,
   int radix)
Integer.parseInt(String s,
   int radix)
Long Long.toString(long l)
Long.parseLong(String s)
Long.toString(long l,
   int radix)
Long.parseLong(String s,
   int radix)
Float Float.toString(float f) Float.parseFloat(String s)
  available for ver. 1.2
Float.valueOf(String s).
doubleValue()
  for version 1.0 & 1.1
Double Double.toString(double d) Double.parseDouble(String s)
  available for ver. 1.2
Double.valueOf(String s).
doubleValue()
  for version 1.0 & 1.1

 

In Chapter 2: Tech: Floating Point we discussed the special values that the floating point types can represent such as infinity and Not-a-Number (NaN). The table here shows the static methods in the Float and Double classes that you can use to determine quickly if a FP variable has such a value.

Floating Point Special Value Determination
Float boolean Float.isNaN(float f)
boolean Float.isInfinite(float f)
Double boolean Double.isNaN(double f)
boolean Double.isInfinite(double f)

 

Latest update: Dec.15.2003

           Tech
OOP in Tech Apps
Complex Number
Histogram Class
  Demo
More Wrappers

           Physics
OOP in Physics
Particle Class
Root Finding
  Demo 1
Newton Methods
  Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.