Auto AdSense

Saturday, 29 November 2014

Java Example to Convert String to primitive byte


   public class StringToPrimitiveByteExample
   {
      
     public static void main(String[] args)
     {
       //declare String object
       String str = new String("10");
      
       /*
       use parseInt method of Byte class to convert String into byte primitive
       data type. This is a static method.
       Please note that this method can throw a NumberFormatException if the string
       is not parsable to byte.
       */
      
       byte b = Byte.parseByte(str);
       System.out.println(b);
      
     }
   }   

No comments:

Post a Comment