First acquaintance with Java (Java wrapper class - Double and Number)

一、Double

    The Double and Float wrapper classes encapsulate the basic types of double and float. They are both subclasses of the Number class and operate on decimals, so the common methods are basically the same.

    The Double class wraps a value of primitive type double in an object. Every object of class Double contains a field of type double. In addition, the class provides several methods to convert double to String, String to double, and other constants and methods that are useful when dealing with doubles.

    1.1 Constructor

    The Double class provides the following two constructors to obtain the Double class object.

    ( 1 ) Double ( double value ): Create a Double class object based on the double parameter.

    (2) Double ( String str ): Constructs a newly allocated Double object, representing a floating point value of double type represented by a string

    Throws a NumberFormatException if it does not take a numeric string as an argument.

    1.2 Common methods

    Common methods of the Double class are as follows:

Common methods of the Double class
method freturn value Function description
byteValue() byte Returns the Double object value as a byte (by casting)
compareTo(Double d) int

Numerically compares two Double objects.

If the two values ​​are equal, it returns 0; if the value of the calling object is less than the value of d, it returns a negative value;

Returns a positive value if the value of the calling object is greater than the value of d.

equals(Object pbj) Boolean Compares this object with the specified object
intValue() int double value returned as int
isNan() boolean true if this double value is a not-a-number (NaN) value; false otherwise
String 返回此 Double 对象的字符串表示形式
valueOf(String str) Double 返回保存用参数字符串 str 表示的 double 值的 Double 对象
doubleValue() double 以 double 形式返回此 Double 对象
longValue() long 以 long 形式返回此 double 的值(通过强制转换为 long 类型)

    1.3  常量  

    Double 类提供了一下常量 :

    ( 1 ) MAX_EXPONENT :返回 int 值,表示有限 double 变量可能具有的最大指数。

    ( 2 ) MIN_EXPONENT  :返回 int 值,表示标准化 double 变量可能具有的最小指数。

    ( 3 )NEGATIVE_INFINITY :返回 double 值,表示保存 double 类型的负无穷大值的常量。

    ( 4 )POSITIVI_INFINITY  :返回 double 值,表示保存 double 类型的正无穷大值的常量。

二、 Number

    抽象类 Number 是 BigDecimal 、 BigInteger 、 Byte 、 Double 、 Float 、 Integer 、 Long 和 Short 类的父类, Number 的子类必须提供将表示的数值转换为 byte 、 double 、 float 、 int 、 long 和 short 的方法。例如: doubleValue() 方法返回双精度值, floatValue() 方法返回浮点值。

Number 类的方法
方法 f返回值 功能描述
byteValue() byte 以 byte 形式返回指定的数值
intValue() int 以 int 形式返回指定的数值
floatValue() float 以 float 形式返回指定的数值
shortValue() short 以 short 形式返回指定的数值
longValue() long 以 long 形式返回指定的数值
doubleValue() double Returns the specified number as a double
    The methods of the Number class are implemented by the subclasses of Number, that is, all the subclasses of the Number class contain the above methods.

  




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325631611&siteId=291194637