Convert String to Byte - Java Language Basics

Java examples for Language Basics:byte

Description

Convert String to Byte

Demo Code

 
public class Main {
 
  public static void main(String[] args) {
    //1. Construct Byte using constructor.
    Byte bObj1 = new Byte("100");
    System.out.println(bObj1);/*from   w  w  w  . j ava2s . co  m*/
   
    //2. Use valueOf method of Byte class. This method is static.
    String str = "100";
    Byte bObj2 = Byte.valueOf(str);
    System.out.println(bObj2);
  }
}

Result


Related Tutorials