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:
- AtomicBoolean toString() method in Java with Examples
- Locale toString() Method in Java with Examples
- Constructor toString() method in Java with Examples
- Matcher toString() method in Java with Examples
- Instant toString() method in Java with Examples
- StringBuffer toString() method in Java with Examples
- StringWriter toString() method in Java with Examples
- ChronoPeriod toString() method in Java with Examples
- DoubleAdder toString() method in Java with Examples
- LongAdder toString() method in Java with Examples
- Scanner toString() method in Java with Examples
- Field toString() method in Java with Examples
- MessageDigest toString() method in Java with Examples
- LocalTime toString() method in Java with Examples
- AtomicIntegerArray 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.


