Java Byte classThe Byte class wraps a primitive byte type value in an object. Its object contains only a single field whose type is byte. Methods:The java.lang.Byte class provides several different methods for converting a byte to a String or vice versa. This class also provides other constants and methods which are useful when we are dealing with byte. Methods | Description |
---|
byteValue() | It returns the value of this Byte as a byte | compare() | It compares the two specified byte values | compareTo() | It compares two Byte objects numerically | compareUnsigned() | It compares the two unsigned byte values | decode() | It is used to decode a String into a Byte | doubleValue() | It returns a double value for this Byte object | equals() | It is used to compare this object against the specified byte object | floatValue() | It returns the value of this Byte as a Float | hashCode() | It returns a hash code for this Byte object | intValue() | It returns an int value for this Byte object | longValue() | It returns a long value for this Byte object | parseByte() | It is used to parse the string argument as a signed decimal byte. | shortValue() | It returns a short value for this Byte object | toString() | It returns a string representation of the Byte object | toUnsignedInt() | It is used to convert the specified byte to an int by an unsigned conversion | toUnsignedLong() | It is used to convert the specified byte to a long by an unsigned conversion | valueOf() | Returns a Byte instance representing the specified byte or string value. |
Example 1Test it NowOutput: 1. 67 is greater than 5
2. Hash code value of 5 is : 5
3. Float value of 67 is : 67.0
4. Integer value of 67 is : 67
5. Decoded value of 123 is : 123
Example 2Test it NowOutput: 1. 67 is greater than 5
2. 5 and 67 are not equal.
3. Long value of 67 is : 67
4. String value of 67 is : 67
5. Double value of 5 is : 5.0
|