toString(short)
The static toString() method of java.lang.Short returns a new String object representing the specified short. The radix is assumed to be 10.This is a static method hence no object of Short class is required for calling this method.
Syntax:
public static String toString(short b)
Parameters: This method accepts a parameter b which is the short value for which string representation is required.
Below is the implementation of toString() method in Java:
Example 1:
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
short a = 515 ;
System.out.println( "String value: "
+ Short.toString(a));
}
}
|
Output:
String value: 515
Example 2:
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
short a = 51 ;
System.out.println( "String value: "
+ Short.toString(a));
}
}
|
toString()
The non-static toString() method of java.lang.Short returns a String object representing this Short object value. The value is converted to signed decimal representation and returned as a string, exactly as if the short value were given as an argument to the toString(short) method.
Syntax:
public String toString()
Parameters: This method do not accepts any parameter.
Returns: This method returns a string representation of the value of this Short object in base 10.
Below is the implementation of toString() method in Java:
Example 1:
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
short a1 = 515 ;
Short a = new Short(a1);
System.out.println( "String value: "
+ a.toString());
}
}
|
Output:
String value: 515
Example 2:
import java.lang.*;
public class GFG {
public static void main(String[] args)
{
short a1 = 51 ;
Short a = new Short(a1);
System.out.println( "String value: "
+ a.toString());
}
}
|
Reference: