Java.lang.Byte.intValue() Method


Description

The java.lang.Byte.intValue() returns the value of this Byte as an int.

Declaration

Following is the declaration for java.lang.Byte.intValue() method

public int intValue()

Specified by

intValue in class Number

Parameters

NA

Return Value

This method returns the numeric value represented by this object after conversion to type int.

Exception

NA

Example

The following example shows the usage of lang.Byte.intValue() method.

package com.tutorialspoint;

import java.lang.*;

public class ByteDemo {

   public static void main(String[] args) {

      // create 2 Byte objects b1, b2
      Byte b1, b2;

      // create 2 int i1, i2
      int i1, i2;

      // assign values to b1, b2
      b1 = new Byte("123");
      b2 = new Byte("-32");

      // assign int values of b1, b2 to i1, i2
      i1 = b1.intValue();
      i2 = b2.intValue();

      String str1 = "int value of Byte " + b1 + " is " + i1;
      String str2 = "int value of Byte " + b2 + " is " + i2;

      // print i1, i2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Let us compile and run the above program, this will produce the following result −

int value of Byte 123 is 123
int value of Byte -32 is -32
java_lang_byte.htm
Advertisements