Java Short.valueOf(String s, int radix) example

Java Short.valueOf(String s, int radix) example

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

In this java tutorial, You will learn how to use valueOf(String s, int radix) method of Short class. This method, Returns a Short object holding the value extracted from the specified String when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed short in the radix specified by the second argument, exactly as if the argument were given to the parseShort(java.lang.String, int) 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 extracted from the specified String when parsed with the radix given by the second argument.

Syntax

public static Short valueOf(String s, int radix) throws NumberFormatException

Parameters

s - the string to be parsed.

radix - the radix to be used in interpreting s.

Returns

A Short object holding the value represented by the string argument in the specified radix.

Throws

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

Java Short valueOf(String s, int radix) example

  • Assign two String values.
  • Short.valueOf(firstValue, 10);It will return the short value of string firstValue with radix 10.
  • Short.valueOf(secondValue, 32);It will return the short value of string secondValue with radix 32.
  • Print the values.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        String firstValue = "45";
        String secondValue = "80";

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

        System.out.println("Short value of string firstValue with radix 10 :- " + result1);
        System.out.println("Short value of string secondValue with radix 32 :- " + result2);
    }
}

output

Short value of string firstValue with radix 10 :- 45
Short value of string secondValue with radix 32 :- 256

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]