Java Short.valueOf(short s) example

Java Short.valueOf(short s) example

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

In this java tutorial, You will learn how to use valueOf(short s) method of Short class. This method, Returns a Short instance representing the specified short value. If a new Short instance is not required, this method should generally be used in preference to the constructor Short(short), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

tags Java

Returns a Short instance representing the specified short value.


public static String valueOf(short s)


s - a short value.


A Short instance representing s.

Java Short valueOf(short s) example

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

public class App {

	public static void main(String[] args) {

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

		value = -20;
		Short secondValue = new Short(value);

		short result1 = Short.valueOf(firstValue);
		short result2 = Short.valueOf(secondValue);

		System.out.println("Value :- " + result1);
		System.out.println("Value :- " + result2);


Value :- 50
Value :- -20

Suggested Posts



Hi there! I am founder of 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][]