Share on Google+Share on Google+

Conversion from String to short

Advertisement
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

Advertisements

Posted on: September 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.