Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Convert String to Short Primitive in Java



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
Updated on: 2020-06-26T10:21:58+05:30

274 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements