Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- * Convert String to Byte example. Program to convert Java
- * String object to Byte object.
- */
- public class StringToByte {
- public static void main(String args[]){
- //new String object
- String str = new String("2");
- //Use Byte(String) constructor
- Byte bObj1 = new Byte(str);
- //OR Use static valueOf(String) method of Byte class
- Byte bObj2 = Byte.valueOf(str); //throws NumberFormatException
- System.out.println("String converted to Byte: " + bObj1);
- }
- }

Post new comment