The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Trail: Learning the Java Language
Lesson: Object Basics and Simple Data Objects

## Converting Strings to Numbers

> The `String` class itself does not provide any methods for converting a `String` to a floating point, integer, or other numerical type. However, four of the "type wrapper" classes (`Integer`, `Double`, `Float`, and `Long`) provide a class method named `valueOf` that converts a `String` to an object of that type. Here's a small, contrived example of the `Float` class's `valueOf`:

> >     String piStr = "3.14159";
> >     Float pi = Float.valueOf(piStr);

| Start of Tutorial > Start of Trail > Start of Lesson | Search Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.