php    php100   android
當前位置:首頁 » Java基礎 »

Java - String valueOf() Method 評論   編輯

Description:

This method has followings variants which depends on the passed paramters. This method returns the string representation of the passed argument.

  • valueOf(boolean b): Returns the string representation of the boolean argument.

  • valueOf(char c) : Returns the string representation of the char argument.

  • valueOf(char[] data) : Returns the string representation of the char array argument.

  • valueOf(char[] data, int offset, int count) : Returns the string representation of a specific subarray of the char array argument.

  • valueOf(double d) : Returns the string representation of the double argument.

  • valueOf(float f) : Returns the string representation of the float argument.

  • valueOf(int i) : Returns the string representation of the int argument.

  • valueOf(long l) : Returns the string representation of the long argument.

  • valueOf(Object obj) : Returns the string representation of the Object argument.

Syntax:

Here is the 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) 

Parameters:

Here is the detail of parameters:

  • See the description.

Return Value :

  • This method returns the string representation.

Example:

import java.io.*;

public class Test{
   public static void main(String args[]){
      double d = 102939939.939;
      boolean b = true;
      long l = 1232874;
      char[] arr = {'a', 'b', 'c', 'd', 'e', 'f','g' };

      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) );
   }
}

This produces following result:

Return Value : 1.02939939939E8
Return Value : true
Return Value : 1232874
Return Value : abcdefg

貢獻/合作者

正在開放中...
 

評論(0條)

  • 還冇有評論!