toString(): This method is available in java.lang.Short class of Java.
Approach 1: When the method does not take any argument.
Syntax:
String java.lang.Short.toString()
This method returns a String object representing this Short's value. The value is converted to signed decimal representation and returned as a string,
Parameters: NA
Returns: a string representation of the value of this object in base 10.
Exceptions: NA
Java
public class ShorttoString {public static void main(String[] args) {Short short1 = 1;System.out.println(short1.toString());}}
Output:
1
Approach 2: When the method takes one argument.
Syntax:
String java.lang.Short.toString(short s)
This method takes one argument of type short as its parameter. This method returns a new String object representing the specified short. The radix is assumed to be 10.
Parameters: One parameter is required for this method.
s: the short to be converted.
Returns: the string representation of the specified short.
Exceptions: NA
Java
public class ShorttoString2 {public static void main(String[] args) {short s = 4;System.out.println(Short.toString(s));}}
Output:
4
No comments:
Post a Comment