How to convert byte to String in java


In this core java tutorial we will learn how to convert byte primitive type to String in java and convert byte object to String with program and examples in java. We will  also understand  When to use convert String to byte primitive type and when when to convert String to byte object in java.





Programs to convert byte to String in java -
  • Program/Example 1 to How to convert byte primitive type to String  in java.
  • Program/Example 2 to How to convert byte object to String in java


Program/Example 1 to How to convert byte primitive type to String  in java.

String.valueOf(byte) method converts byte primitive type to String  in java.

package convertByteToStringPkg;
public class ConvertByteToStringExample1 {
   public static void main(String[] args) {
         
          byte b = 12;
          String string = String.valueOf(b);
          System.out.println("string = "+string);
  
   }
}
/*OUTPUT
string = 12

*/




Program/Example 2 to How to convert byte object to String in java

toString() method of java.lang.Byte class convert byte object to String in java.

package convertByteToStringPkg;
public class ConvertByteObjectToStringExample2 {
   public static void main(String[] args) {
          Byte byteObject = 12;
          String string = byteObject.toString();
          System.out.println("string = "+string);
  
   }
}
/*OUTPUT
string = 12
*/



Summary -

In this core java tutorial we learned conversion of byte primitive type to String in java and convert byte object to String with program and examples in java. We also understood  when to use convert String to byte primitive type and when when to convert String to byte object in java.




Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>

Collection - List, Set and Map all properties in tabular form



eEdit
Must read for you :