Java Short.toString() example

Java Short.toString() example

By Yashwant Chavan, Views 11, Date 16-May-2018

In this java tutorial, You will learn how to use toString() method of Short class. This method, Returns a String object representing this Short's 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.

tags Java

Returns a String object representing this Short's value.

Syntax

public String toString()

Returns

A string representation of the value of this object in base 10.

Java Short toString() example

  • Assign two short values.
  • Create an instance of short values e.g new Short(value);
  • firstValue.toString();It will return the string value of firstValue.
  • secondValue.toString();It will return the string value of secondValue.
  • Print the values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        short value1 = 50;
        Short firstValue = new Short(value1);

        short value2 = -20;
        Short secondValue = new Short(value2);

        String result1 = firstValue.toString();
        String result2 = secondValue.toString();

        System.out.println("String value of firstValue :- " + result1);
        System.out.println("String value of secondValue :- " + result2);
    }
}

output

String value of firstValue :- 50
String value of secondValue :- -20

Suggested Posts

Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]