
- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java.lang.Float.compare() Method
Description
The java.lang.Float.compare() method compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the call −
new Float(f1).compareTo(new Float(f2))
Declaration
Following is the declaration for java.lang.Float.compare() method
public static int compare(float f1, float f2)
Parameters
f1 − This is the first float to compare.
f2 − This is the second float to compare.
Return Value
This method returns the value 0 if f1 is numerically equal to f2; a value less than 0 if f1 is numerically less than f2; and a value greater than 0 if f1 is numerically greater than f2.
Exception
NA
Example
The following example shows the usage of java.lang.Float.compare() method.
package com.tutorialspoint; import java.lang.*; public class FloatDemo { public static void main(String[] args) { // compares the two specified float values float f1 = 22.30f; float f2 = 88.67f; int retval = Float.compare(f1, f2); if(retval > 0) { System.out.println("f1 is greater than f2"); } else if(retval < 0) { System.out.println("f1 is less than f2"); } else { System.out.println("f1 is equal to f2"); } } }
Let us compile and run the above program, this will produce the following result −
f1 is less than f2
java_lang_float.htm
Advertisements