In this tutorial we will learn how to convert a string type data to short type data.
In this tutorial we will learn how to convert a string type data to short type data.In this tutorial we will learn how to convert a string type data to short type data.
This program will take a String value from mystring variable. The line short myshort = Short.parseShort(mystring); converts the mystring string type value to myshort short type value. The parseShort() method coverts the any type data to short type data.
class Stringtoshort { public static void main(String[] args) { try { String mystring = "102"; short myshort = Short.parseShort(mystring); System.out.println("Converted value from String to short is: " + myshort); } catch (Exception e) { System.out.println(" Error " + e); } } };