Web | This Site

Java Basics
Java Object Oriented
Java Advanced
Java Useful References
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java - valueOf() Method

## Description:

The valueOf method returns the relevant Number Object holding the value of the argument passed. The argument can be a primitive data type, String etc.

This method is a static method. The method can take two arguments, where one is a String and the other is a radix.

## Syntax:

All the variant of this method are given below:

    static Integer valueOf(int i)
    static Integer valueOf(String s)
    static Integer valueOf(String s, int radix)

## Parameters:

Here is the detail of parameters:

- int : An int for which Integer representation would be returned.

- String s : A String for which Integer representation would be returned.

- int radix : This would be used to decide the value of returned Integer based on passed String.

## Return Value :

- valueOf(int i): This returns an Integer object holding the value of the specified primitive.

- valueOf(String s): This returns an Integer object holding the value of the specified string representation.

- valueOf(String s, int radix): This returns an Integer object holding the integer value of the specified string representation, parsed with the value of radix.

## Example:

    public class Test{
       public static void main(String args[]){

          Integer x =Integer.valueOf(9);
          Double c = Double.valueOf(5);
          Float a = Float.valueOf("80");

          Integer b = Integer.valueOf("444",16);

          System.out.println(x);
          System.out.println(c);
          System.out.println(a);
          System.out.println(b);
         }
    }

This produces following result:

    9
    5.0
    80.0
    1092

Advertisement

Online Image Processing

Indian Baby Names