Java Program to convert String to short primitive

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Nov-2018 17:03:33
Advertisements