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



Description

The valueOf () method in Java has the following options, which depend on the parameters passed. This method returns a string representation of the passed argument.

  • valueOf (boolean b) - returns a string representation of the logical argument.
  • valueOf (char c) - returns a string representation of a char argument.
  • valueOf (char [] data) - returns a string representation of a array char arguments.
  • valueOf (char [] data, int offset, int count) - returns a string representation of a particular subarray array of char arguments.
  • valueOf (double d) - returns a string representation double argument
  • valueOf (float f) - returns a string representation of the float argument.
  • valueOf (int i) - returns a string representation of an int argument.
  • valueOf (long l) - returns a string representation of a long argument.
  • valueOf (Object obj) - returns a string representation of a argument object.

Syntax

Syntax of this method:

static String valueOf(boolean b) 
or 
static String valueOf(char c) 
or
static String valueOf(char[] data) 
or
static String valueOf(char[] data, int offset, int count) 
or
static String valueOf(double d) 
or
static String valueOf(float f) 
or
static String valueOf(int i)
or
static String valueOf(long l)
or
static String valueOf(Object obj) 
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • see Description.

Return value:

  • In Java, valueOf () returns a string representation of the passed argument.

Sample Code

import java.io.*;

public class Test {

   public static void main(String args[]) {
      double d = 102939939.939;
      boolean b = true;
      long l = 1232874;
      char[] arr = { 'y', 'a', 'r', 'a', 'n', '0', '7' };

      System.out.println("Return value: " + String.valueOf(d));
      System.out.println("Return value: " + String.valueOf(b));
      System.out.println("Return value: " + String.valueOf(l));
      System.out.println("Return value: " + String.valueOf(arr));
   }
}
click below button to copy the code. By - java tutorial - team

Output

Return value: 1.02939939939E8
Return value: true
Return value: 1232874
Return value: yaran07

Related Searches to Java Strings valueOf() method