Java Program to convert String to short primitive


Use the parseShort() method to convert String to short primitive. It parses the string argument as a signed short.

Firstly, we have set a string.

String str = "99";

Now, we have taken a short primitive and included the string value.

short val = Short.parseShort(str);

The following is an example to convert String to short primitive.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      String str = "99";
      short val = Short.parseShort(str);
      System.out.println(val);
   }
}

Output

99

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements