Good example code using Byte class methods.
package wclasses;
public class SampleByte {
public static void main(String as[])
{
//constructors
byte b=10;
Byte b1= new Byte(b);
Byte b2= new Byte("10");
// Byte to primitive byte
byte bi=b1.byteValue();
int bi1=b1.intValue();
System.out.println(bi);
System.out.println(bi1);
//byte to string
String s1=b1.toString();
String s2=Byte.toString(b);
System.out.println(s1);
System.out.println(s2);
//String to primitive byte
byte pi2=Byte.parseByte(s2);
System.out.println(pi2);
//String to wrapper Byte
Byte b3= new Byte("10");
Byte b4=Byte.valueOf("100");
System.out.println(b3);
System.out.println(b4);
//Byte wrapper to string
String s3=b4.toString();
}
}
output:
10
10
10
10
10
10
100
0 comments:
Post a Comment