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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

String value: 515

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

String value: 515

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

String value: 51

Reference:



My Personal Notes arrow_drop_up

Image
Check out this Author's contributed articles.

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.