Java.lang.Short toString() method in Java with Examples
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:
// Java program to demonstrate working // of java.lang.Short.toString() method import java.lang.*; public class GFG { public static void main(String[] args) { short a = 515; // using toString() System.out.println("String value: " + Short.toString(a)); } } |
String value: 515
Example 2:
// Java program to demonstrate working // of java.lang.Short.toString() method import java.lang.*; public class GFG { public static void main(String[] args) { short a = 51; // using toString() System.out.println("String value: " + Short.toString(a)); } } |
String value: 51
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:
// Java program to demonstrate working // of java.lang.Short.toString() method import java.lang.*; public class GFG { public static void main(String[] args) { short a1 = 515; // create Short object Short a = new Short(a1); // using toString() System.out.println("String value: " + a.toString()); } } |
String value: 515
Example 2:
// Java program to demonstrate working // of java.lang.Short.toString() method import java.lang.*; public class GFG { public static void main(String[] args) { short a1 = 51; // create Short object Short a = new Short(a1); // using toString() System.out.println("String value: " + a.toString()); } } |
String value: 51
Reference:
- https://docs.oracle.com/javase/9/docs/api/java/lang/Short.html#toString–
- https://docs.oracle.com/javase/9/docs/api/java/lang/Short.html#toString-short-
Recommended Posts:
- DigestOutputStream.toString() method in Java with Examples
- LongAccumulator toString() method in Java with Examples
- Calendar toString() Method in Java with Examples
- Optional toString() method in Java with examples
- OffsetTime toString() method in Java with examples
- BigDecimal toString() Method in Java with Examples
- AtomicBoolean toString() method in Java with Examples
- LocalDateTime toString() method in Java with Examples
- Level toString() method in Java with Examples
- Boolean toString() method in Java with examples
- Byte toString() method in Java with examples
- Matcher toString() method in Java with Examples
- AtomicLongArray toString() method in Java with Examples
- ZoneId toString() method in Java with Examples
- AbstractCollection toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



