java tutorial - Java valueOf() method - java programming - learn java - java basics - java for beginners



Java numbers value of

Learn Java - Java tutorial - Java numbers value of - Java examples - Java programs

Description

  • The valueOf () method - returns the corresponding numeric object containing the value of the passed argument, in simple words - converts it to the desired data type.
  • The argument can be converted to int, double, float and other data types, for example, you can convert a string to a number.
  • The valueOf () method in Java is a static method. A method can take two arguments, where one is a string and another number system.

Syntax

All variants of the method are given below:

static Integer valueOf(int i)
static Integer valueOf(String s)
static Integer valueOf(String s, int radix)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • i - int, for which the integer representation will be returned.
  • s - String for which the integer representation will be returned.
  • radix - can be used to decide what integer value will be returned to based on the String passed.

Return value

  • valueOf (int i): returns an integer object containing the value of the identified type.
  • valueOf (String s): returns an Integer object containing the value of the identified string representation.
  • valueOf (String s, int radix): returns an integer object taking an integer value of the identified string illustration, described with the value of the integer system.

Sample Code

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);
   }
}
click below button to copy the code. By - java tutorial - team

Output

9
5.0
80.0
1092

Related Searches to Java valueOf() method