See the Tutorial List

Double Class


Below are the Methods of Double class and their example

1. toString()

Syntax:

	
public String toString(double b)
	

Example:

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

double-class


2. valueOf()

Syntax:

	
public static Double valueOf(double b)
	

Example:

	
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); 
     }
}
	

double-class-example


3. parseDouble()

Syntax:

	
public static double parseDouble(String val)
             throws NumberFormatException
	

Example:

	
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);
     }
}
	

double-class-example


4. byteValue()

Syntax

	
public byte byteValue()
	

5. shortValue()

Syntax

	
public short shortValue()
	

6. intValue()

Syntax

	
public int intValue()
	

7. longValue()

Syntax

	
public long longValue()
	

8. doubleValue()

Syntax

	
public double doubleValue()
	

9. floatValue()

Syntax

	
public float floatValue()
	

Example:

	
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());
     }
}
	

double-class-example


10. hashCode()

Syntax:

	
public inthashCode()
	

Example:

	
public class DoubleDemo1
{ 
    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); 
     }
}
	

double-class-example


11. isNaN()

Syntax:

	
public booleanisNaN()
	

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("isNaN(x) = " + x.isNaN());  
     }
}
	

double-class-example


12. isInfinite()

Syntax:

	
public booleanisInfinite()
	

Example:

	
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()));   
     }
}
	

double-class-example


13. toHexString()

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)); 	
    }
}
	

double-class-example


14. doubleToLongBits()

Syntax:

	
public static long doubleToLongBits(double val)
	

Example:

	
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);        
}
}
	

double-class-example


15. doubleToRawLongBits()

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);        
	}
}
	

double-class-example


16. LongBitsToDouble()

Syntax

	
public static double LongBitsToDouble(long b)
	

Example:

	
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);       
	}
}
	

double-class-example


17. equals()

Syntax:

	
public boolean equals(Object obj)
	

Example:

	
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); 

	}
}
	

double-class-example


18. compareTo()

Syntax:

	
public intcompareTo(Double b)
	

Example:

	
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); 

	}
}
	

double-class-example


19. compare()

Syntax:

	
public static int compare(double x,double y)
	

Example:

	
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); 

	}
}
	

double-class-example