Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » FundamentalRSS Feeds

Byte Wrapper Class

Posted By: Shawn Mills     Category: Java     Views: 4168

This article explains about Byte wrapper class in java.

Byte wrapper class is used to wrap primitive data type byte value in an object. 

Examples of Byte Wrapper Class

Example 1 :  Convert byte to Byte object 

public class byteToByte 
{
  public static void main(String[] args) 
  {
    byte b = 1;
  
    Byte bObj = new Byte(b);
    System.out.println(bObj);
  }
}

Output 
1
 
This example shows how a byte primitive value can be converted to Byte object.

Example 2 : Convert Byte object to String object

public class ByteToString 
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    String s = bObj.toString();
    System.out.println("Converted value of Byte object into string object is " + s);
  }
}

Output 
Converted value of Byte object into string object is 1  

This example shows how a Byte object can be converted into String object.

Example 3 : Convert Byte object to int

public class ByteToint 
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    int i = bObj.intValue();
    System.out.println(i);
  }
}
 
Output 
1  

This example shows how a Byte object can be converted into int.


Example 4 : Convert Byte object to short

public class ByteToshort
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    short sh = bObj.shortValue();
    System.out.println(sh);
  }
}
 
Output 
1  

This example shows how a Byte object can be converted into short.


Example 5 : Convert Byte object to long

public class ByteTolong
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    long l = bObj.longValue();
    System.out.println(l);
  }
}
 
Output 

This example shows how a Byte object can be converted into long.


Example 6 : Convert Byte object to float

public class ByteTofloat
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    float f = bObj.floatValue();
    System.out.println(f);
  }
}
 
Output 
1.0  

This example shows how a Byte object can be converted into float.


Example 7 : Convert Byte object to double

public class ByteTodouble
{
 
  public static void main(String[] args) 
  {
    Byte bObj = new Byte("1");
 
    double d = bObj.doubleValue();
    System.out.println(d);
  }
}
 
Output 
1.0  

This example shows how a Byte object can be converted into double.

  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Byte Wrapper Class Or get search suggestion and latest updates.

Shawn Mills
Shawn Mills author of Byte Wrapper Class is from Phoenix, United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!