O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Doing Stuff with Strings

Now that it is clearer how Strings assignments and concatenation work, we will turn our attention to performing miscellaneous but frequently useful String operations.

Convert Different Variables to Strings

In this section we'll look at a couple of ways to convert different kinds of things into Strings.

Using valueOf()

Often you need to convert certain types to Strings in order to pass them to a method that accepts only a String. You can do this using the valueOf() method of the String class.

System.out.println(String.valueOf(Math.PI));
//prints 3.141592653589793

There are several valueOf() methods defined for the String class, each of which takes different parameters (which means that the valueOf() method is overloaded ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required