Package java.lang
Interface Comparable<T>
- All Known Subinterfaces:
Delayed,RunnableScheduledFuture<V>,ScheduledFuture<V>
- All Known Implementing Classes:
Authenticator.RequestorType,BigDecimal,BigInteger,Bits,Boolean,Byte,ByteBuffer,Calendar,Character,CharBuffer,Charset,ClientInfoStatus,CollationKey,CollationKeyICU,Date,Date,Double,DoubleBuffer,ElementType,Enum,File,Float,FloatBuffer,Formatter.BigDecimalLayoutForm,GregorianCalendar,IntBuffer,Integer,KeyRep.Type,Long,LongBuffer,MappedByteBuffer,Normalizer.Form,ObjectStreamField,OpenSSLCipher.Mode,OpenSSLCipher.Padding,PKIFailureInfo,PKIStatus,Proxy.Type,ResponseSource,RetentionPolicy,RoundingMode,RouteInfo.LayerType,RouteInfo.TunnelType,RowIdLifetime,Short,ShortBuffer,SSLEngineResult.HandshakeStatus,SSLEngineResult.Status,String,TestLevel,Thread.State,Time,Timestamp,TimeUnit,URI,UUID
public interface Comparable<T>
This interface should be implemented by all classes that wish to define a
natural order of their instances.
Collections.sort(java.util.List<T>) and java.util.Arrays#sort can then
be used to automatically sort lists of classes that implement this interface.
The order rule must be both transitive (if x.compareTo(y) < 0 and
y.compareTo(z) < 0, then x.compareTo(z) < 0 must hold) and
invertible (the sign of the result of x.compareTo(y) must be equal to the
negation of the sign of the result of y.compareTo(x) for all combinations of
x and y).
In addition, it is recommended (but not required) that if and only if the
result of x.compareTo(y) is zero, then the result of x.equals(y) should be
true.
-
Method Summary
-
Method Details
-
compareTo
Compares this object to the specified object to determine their relative order.- Parameters:
another- the object to compare to this instance.- Returns:
- a negative integer if this instance is less than
another; a positive integer if this instance is greater thananother; 0 if this instance has the same order asanother. - Throws:
ClassCastException- ifanothercannot be converted into something comparable tothisinstance.
-