Java Short.valueOf(String s) example

Java Short.valueOf(String s) example

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

In this java tutorial, You will learn how to use valueOf(String s) method of Short class. This method, Returns a Short object holding the value given by the specified String. The argument is interpreted as representing a signed decimal short, exactly as if the argument were given to the parseShort(java.lang.String) method. The result is a Short object that represents the short value specified by the string.

tags Java

Returns a Short object holding the value given by the specified String.

Syntax

public static Short valueOf(String s) throws NumberFormatException

Parameters

s - the string to be parsed.

Returns

A Short object holding the value represented by the string argument.

Throws

NumberFormatException - If the String does not contain a parsable short.

Java Short valueOf(String s) example

  • Assign two String values.
  • Short.valueOf("45");It will return the short value of string value.
  • Short.valueOf("80");It will return the short value of string value.
  • Print the values.
package com.technicalkeeda;

public class App {

	public static void main(String[] args) {

		short result = Short.valueOf("45");
		System.out.println("Short value of string :- " + result);
		result = Short.valueOf("80");
		System.out.println("Short value of string :- " + result);
	}
}

output

Short value of string :- 45
Short value of string :- 80

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]