Home Tutorial Java Corejava Dataconversion String Conversion from String to short

 
 

Conversion from String to short
Posted on: September 3, 2010 at 12:00 AM
In this tutorial we will learn how to convert a string type data to short type data.

Conversion from String to short:

In this tutorial we will learn how to convert a string type data to short type data.

Description:

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.

Code:

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);
		}
	}
};
 

Output:

Download this code

Related Tags for Conversion from String to short:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.