java 在双引号加双引号

The Double class is a wrapper class that is used to wrap a value of the primitive double type in an object. An object of type Double contains a single field whose type is double. The Double class extends Number class and implements Comparable interface.

Double类是包装器类,用于将原始double类型的值包装在对象中。 类型为Double的对象包含一个类型为double的字段。 Double类扩展Number类并实现Comparable接口。

In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double. Declaration of the class is given below.

另外,此类提供了几种将double转换为String和将String转换为double的方法,以及其他在处理double时有用的常量和方法。 该类的声明在下面给出。

(Declaration:)

public final class Double extends Number implements Comparable<Double>

Here we are explaining the methods of Double class and their example.

在这里,我们解释Double类的方法及其示例。

(1. toString())

It returns a new String representing of specified double object. Syntax of the method is given below.

它返回一个新的String,它表示指定的double对象。 该方法的语法如下。

(Syntax:)

public String toString(double b)

(Example:)

Lets take an example to get string object of a double type. We used toString() method which is static so we can call it by using the class name. See the below example.

让我们以获取双精度类型的字符串对象为例。 我们使用了toString()方法,该方法是静态的,因此我们可以使用类名来调用它。 请参见以下示例。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		System.out.println("toString(a) = " + Double.toString(a)); 
     }
}




java中双引号的转义 java双引号里面再加双引号_object


(2. valueOf() )

This method returns a Double instance representing the specified double value. This method should generally be used in preference to the constructor Double(double). It takes a single argument of double type.

此方法返回一个Double实例,该实例表示指定的double值。 通常应优先于构造方法Double(double)使用此方法。 它需要一个双精度类型的参数。

(Syntax:)

public static Double valueOf(double b)

(Example:)

In this example, we are using valueOf() method that returns instance of Double class which represents the specified double type.

在此示例中,我们使用valueOf()方法返回Double类的实例,该实例表示指定的double类型。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
        String b = "85";
        Double x = Double.valueOf(a); 
	   	System.out.println("valueOf(a) = " + x); 
        x = Double.valueOf(b); 
		System.out.println("ValueOf(b) = " + x); 
     }
}


java中双引号的转义 java双引号里面再加双引号_字符串_02


(3. parseDouble())

This method returns a double value of the specified string value. We can use it to get a double value from string type value. It takes a single String type argument.

此方法返回指定字符串值的双精度值。 我们可以使用它从字符串类型值中获取一个双精度值。 它需要一个String类型的参数。

(Syntax:)

public static double parseDouble(String val) throws NumberFormatException

(Example:)

Lets take an example in which we have a string type variable and getting its double value using the parseDouble() method.

让我们举一个例子,其中我们有一个字符串类型的变量,并使用parseDouble()方法获取其双parseDouble()值。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
	String b = "85";
        double x = Double.parseDouble(b); 
System.out.println("parseDouble(b) = " + x);
     }
}


java中双引号的转义 java双引号里面再加双引号_字符串_03


(4. byteValue() )

This method is used to get a primitive type double value from Double object. It returns the numeric value represented by this object after conversion to type double.

此方法用于从Double对象获取基本类型double值。 转换为double类型后,它将返回此对象表示的数值。

(Syntax)

public byte byteValue()

(5. shortValue() )

This method returns the value of this Double as a double after a widening primitive conversion. Syntax of this method is given below.

扩展原始转换后,此方法以double形式返回此Double的值。 该方法的语法如下。

(Syntax)

public short shortValue()

(6. intValue() )

The intValue() method returns the value of this Double as a primitive int type after a widening primitive conversion. Syntax of this method is given below.

在扩展原始转换后, intValue()方法将此Double的值作为原始int类型返回。 该方法的语法如下。

(Syntax)

public int intValue()

(7. longValue() )

The longValue() method returns the value of this Double type as a long type after a widening primitive conversion. Syntax of this method is given below.

longValue()方法在扩展原始图元转换后以Double类型的形式返回此Double类型的值。 该方法的语法如下。

(Syntax)

public long longValue()

(8. doubleValue() )

It returns the value of this Double type as a double type after a widening primitive conversion. Syntax of this method is given below.

扩展原始转换后,它以Double类型返回此Double类型的值。 该方法的语法如下。

(Syntax)

public double doubleValue()

(9. floatValue() )

This method is used to get value of this Double type as a float type after a widening primitive conversion. Syntax of this method is given below.

在扩展原始转换后,此方法用于获取此Double类型的值作为浮点类型。 该方法的语法如下。

(Syntax)

public float floatValue()

(Example:)

Lets take an example to convert double type to int, long and float type values. In this example, we are using intValue(), floatValue(), doubleValue() methods.

让我们以将double类型转换为int,long和float类型的值为例。 在此示例中,我们使用intValue(), floatValue(), doubleValue()方法。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		Double obj = new Double(a); 
		System.out.println("bytevalue(obj) = " + obj.byteValue()); 
		System.out.println("shortvalue(obj) = " + obj.shortValue()); 
		System.out.println("intvalue(obj) = " + obj.intValue()); 
		System.out.println("longvalue(obj) = " + obj.longValue()); 
		System.out.println("doublevalue(obj) = " + obj.doubleValue()); 
		System.out.println("floatvalue(obj) = " + obj.floatValue());
     }
}


java中双引号的转义 java双引号里面再加双引号_java_04


(10. hashCode() )

This method is used to get hash code of a double type value. It returns an int value of double object.

此方法用于获取双精度类型值的哈希码。 它返回一个double型对象的int值。

(Syntax:)

public inthashCode()

(Example:)

public static void main(String[] args) 
    { 
        double a = 46.23; 
        Double obj = new Double(a); 
        int x = obj.hashCode(); 
   	  	System.out.println("hashcode(x) = " + x); 
     }
}


java中双引号的转义 java双引号里面再加双引号_java中双引号的转义_05


(11. isNaN())

This method returns a boolean value either true or false. It returns true, if this Double value is a Not-a-Number (NaN), false otherwise.

数字(NaN)

(Syntax:)

public booleanisNaN()

(Example:)

Lets take an example to check whether the given double value is NaN or not. See the below example.

让我们以一个示例检查给定的double值是否为NaN。 请参见以下示例。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
        Double obj = new Double(a); 
        Double x = Double.valueOf(a); 
    	System.out.println("isNaN(x) = " + x.isNaN());  
     }
}


java中双引号的转义 java双引号里面再加双引号_反射_06


(12. isInfinite())

This method is used to check whether the double value is infinitely large in magnitude. It returns a boolean value either true or false. Syntax of this method is given below.

此方法用于检查double值的大小是否无限大。 它返回布尔值true或false。 该方法的语法如下。

(Syntax:)

public booleanisInfinite()

(Example:)

We can use this method to check the range of Double value whether it lies under infinitely or not.

我们可以使用此方法检查Double值的范围是否位于无限下方。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
        Double obj = new Double(a); 
        Double x = Double.valueOf(a);
        x = Double.valueOf(Double.POSITIVE_INFINITY + 1); 
   	    System.out.println("Double.isInfinite(x) = " + Double.isInfinite(x.doubleValue()));   
     }
}


java中双引号的转义 java双引号里面再加双引号_反射_07


(13. toHexString())

This method is used to get a hexadecimal string representation of the double argument. It takes a double type argument that would be convert into hexadecimal value. Syntax of this method is given below.

此方法用于获取double参数的十六进制字符串表示形式。 它使用一个双精度类型参数,该参数将转换为十六进制值。 该方法的语法如下。

(Syntax:)

public static String toHexString(double val)

(Example:)

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
        Double obj = new Double(a); 
        Double x = Double.valueOf(a);
	    System.out.println("Double.toHexString(a) = " + Double.toHexString(a));         
    }
}


java中双引号的转义 java双引号里面再加双引号_java_08


(14. doubleToLongBits() )

This method is used to get representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout. It takes a floating-point argument. Syntax of this method is given below.

此方法用于根据IEEE 754浮点“单一格式”位布局来获取指定浮点值的表示形式。 它需要一个浮点参数。 该方法的语法如下。

(Syntax:)

public static long doubleToLongBits(double val)

(Example:)

In this example, we are using floattointbits() method that returns a bit layout of floating-point value.

在此示例中,我们使用floattointbits()方法返回浮点值的位布局。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		Double obj = new Double(a); 
		long x = Double.doubleToLongBits(a); 
		System.out.println("Double.doubleToLongBits(a) = " + x);        
	}
}


java中双引号的转义 java双引号里面再加双引号_java_09


(15. doubleToRawLongBits())

This method returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values. Syntax of this method is given below.

此方法根据IEEE 754浮点“单一格式”位布局返回指定的浮点值的表示形式,并保留非数字(NaN)值。 该方法的语法如下。

(Syntax:)

public static long doubleToRawLongBits(double val)

(Example:)

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		Double obj = new Double(a); 
		long x = Double.doubleToRawLongBits(a); 
		System.out.println("Double.doubleToRawLongBits(a) = " + x);        
	}
}


java中双引号的转义 java双引号里面再加双引号_java中双引号的转义_10


(16. LongBitsToDouble() )

This method is used to get the double floating-point value with the same bit pattern. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "single format" bit layout. Syntax of this method is given below.

此方法用于获取具有相同位模式的双浮点值。 根据IEEE 754浮点“单一格式”位布局,该参数被认为是浮点值的表示。 该方法的语法如下。

(Syntax)

public static double LongBitsToDouble(long b)

(Example:)

Lets take an example to understand the intbitstofloat() method that returns floating-point value.

让我们以一个示例来了解返回浮点值的intbitstofloat()方法。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		Double obj = new Double(a); 
		long x = Double.doubleToLongBits(a); 
        double y = Double.longBitsToDouble(x); 
		System.out.println("Double.LongBitsToDouble(x) = " + y);       
	}
}


java中双引号的转义 java双引号里面再加双引号_字符串_11


(17. equals() )

The equals() method compares an object to the specified object. It returns true if objects are same; false otherwise. Syntax of this method is given below.

equals()方法将一个对象与指定对象进行比较。 如果对象相同,则返回true;否则,返回true。 否则为假。 该方法的语法如下。

(Syntax:)

public boolean equals(Object obj)

(Example:)

We are comparing two double objects using the equals method that returns true if both the objects are true.

我们正在使用equals方法比较两个double对象,如果两个对象都为true,则返回true。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		String b ="12";
		Double obj = new Double(a);
		Double obj1 = new Double(b); 
		boolean x = obj.equals(obj1); 
		System.out.println("obj.equals(obj1) = " + x); 
	}
}


java中双引号的转义 java双引号里面再加双引号_java中双引号的转义_12


(18. compareTo())

This method is used to compare two double objects numerically. It returns 0, if the both double objects are equal. It returns less the 0, if one double object is less than argument object. It returns greater than 0, if one double object is numerically greater than the argument double object. Syntax of this method is given below.

此方法用于数值比较两个双精度对象。 如果两个双精度对象相等,则返回0。 如果一个双精度对象小于参数对象,则返回的值小于0。 如果一个双精度对象在数值上大于参数双精度对象,则返回大于0的值。 该方法的语法如下。

(Syntax:)

public intcompareTo(Double b)

(Example:)

In this example, we are comparing two double objects using compareTo() method that compares two double objects numerically and returns a numeric value.

在此示例中,我们使用compareTo()方法比较两个双精度对象,该方法对两个双精度对象进行数值比较并返回一个数值。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		String b ="12";
		Double obj = new Double(a);
		Double obj1 = new Double(b); 
		int x = obj.compareTo(obj1); 
		System.out.println("obj.compareTo(obj1) = " + x); 
	}
}


java中双引号的转义 java双引号里面再加双引号_java中双引号的转义_13


(19. compare())

It is used to compare two double values numerically. The value returned is identical to what would be returned by. Syntax of this method is given below.

用于数值比较两个双精度值。 返回的值与将返回的值相同。 该方法的语法如下。

(Syntax:)

public static int compare(double x,double y)

(Example:)

We can use compare method to compare two double values. It returns 0 if both are equal else returns either negative or positive numerical value.

我们可以使用compare方法比较两个double值。 如果两者相等,则返回0,否则返回正数或负数。

public class DoubleDemo1
{ 
    public static void main(String[] args) 
    { 
        double a = 46.23; 
		String b ="12";
		Double obj = new Double(a);
		Double obj1 = new Double(b); 
		int x = Double.compare(obj, obj1); 
		System.out.println("compare(obj, obj1) = " + x); 
	}
}


java中双引号的转义 java双引号里面再加双引号_字符串_14


翻译自: https://www.studytonight.com/java/double-class.php

java 在双引号加双引号