Home Tutorial Java Corejava Dataconversion String Conversion from String to byte

 
 

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

Conversion from String to byte:

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

Description:

This program will take a String value from mystring variable. The line byte mybyte = Byte.parseByte(mystring); converts the mystring string type value to mybyte byte type value. The parseByte() method coverts the any type data to byte type data.

Code:

class Stringtobyte {
	public static void main(String[] args) {
		try {
			String mystring = "10";
			byte mybyte = Byte.parseByte(mystring);
			System.out.println("Converted value from String to byte is: "
					+ mybyte);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
}
 

Output:

Download this code

Related Tags for Conversion from String to byte:


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.