Package java.lang
Interface Comparable<T>
-
- All Known Subinterfaces:
Delayed,RunnableScheduledFuture<V>,ScheduledFuture<V>
- All Known Implementing Classes:
AlphabeticIndex.Bucket.LabelType,Annotation,AsyncTask.Status,Authenticator.RequestorType,BigDecimal,BigDecimal,BigInteger,BinaryHprof.ControlSettings,BinaryHprof.Tag,Boolean,BuddhistCalendar,Byte,ByteArrayWrapper,ByteBuffer,BytesTrie.Result,ByteString,Calendar,Calendar,CertificateEntry.LogEntryType,Character,CharBuffer,Charset,CharsetMatch,ChineseCalendar,CipherSuite,ClientInfoStatus,CollationKey,CollationKey,CollationKeyICU,CompactDecimalFormat.CompactStyle,Configuration,CopticCalendar,CRLReason,Currency.CurrencyUsage,DangiCalendar,Date,Date,DateFormat.BooleanAttribute,DigitallySigned.HashAlgorithm,DigitallySigned.SignatureAlgorithm,DisplayContext,DisplayContext.Type,Double,DoubleBuffer,ElementType,EncodedValue,Enum,ErrorCode,EthiopicCalendar,FieldId,File,Float,FloatBuffer,Formatter.BigDecimalLayoutForm,GenderInfo.Gender,GenderInfo.ListGenderStyle,GregorianCalendar,GregorianCalendar,HeadersMode,HebrewCalendar,HprofData.ThreadEventType,ICUResource.Key,ICUResourceBundle.OpenType,IDNA.Error,IndianCalendar,IntBuffer,Integer,IslamicCalendar,IslamicCalendar.CalculationType,JapaneseCalendar,KeyRep.Type,ListFormatter.Style,LocaleDisplayNames.DialectHandling,LocaleDisplayNamesImpl.DataTableType,Long,LongBuffer,MappedByteBuffer,MeasureFormat.FormatWidth,MessagePattern.ApostropheMode,MessagePattern.ArgType,MessagePattern.Part.Type,MessagePatternUtil.MessageContentsNode.Type,MethodId,Normalizer.Form,Normalizer2.Mode,ObjectStreamField,OpenSSLCipher.Mode,OpenSSLCipher.Padding,PersianCalendar,PKIFailureInfo,PKIStatus,PluralRanges,PluralRules.FixedDecimal,PluralRules.KeywordStatus,PluralRules.PluralType,PluralRules.SampleType,PluralRules.StandardPluralCategories,Protocol,ProtoId,Proxy.Type,RawCollationKey,Region,Region.RegionType,RelativeDateTimeFormatter.AbsoluteUnit,RelativeDateTimeFormatter.Direction,RelativeDateTimeFormatter.RelativeUnit,RelativeDateTimeFormatter.Style,RetentionPolicy,RoundingMode,Row,Row.R2,Row.R3,Row.R4,Row.R5,RowIdLifetime,SdkConstant.SdkConstantType,SearchIterator.ElementComparisonType,Short,ShortBuffer,SignedCertificateTimestamp.Origin,SignedCertificateTimestamp.SignatureType,SignedCertificateTimestamp.Version,SpoofChecker.RestrictionLevel,SSLEngineResult.HandshakeStatus,SSLEngineResult.Status,String,StringTrieBuilder.Option,TableOfContents.Section,TaiwanCalendar,Thread.State,Time,Timestamp,TimeUnit,TimeZone.SystemTimeZoneType,TimeZoneFormat.GMTOffsetPatternType,TimeZoneFormat.ParseOption,TimeZoneFormat.Style,TimeZoneFormat.TimeType,TimeZoneGenericNames.GenericNameType,TimeZoneGenericNames.Pattern,TimeZoneNames.NameType,TlsVersion,TypeList,ULocale,ULocale.Category,ULocale.Minimize,UnicodeSet,UnicodeSet.ComparisonStyle,UnicodeSet.SpanCondition,UnicodeSetSpanner.CountMethod,UnicodeSetSpanner.TrimOption,URI,UScript.ScriptUsage,UUID,VerifiedSCT.Status,VersionInfo,Xml.Encoding
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>)andjava.util.Arrays#sortcan then be used to automatically sort lists of classes that implement this interface.The order rule must be both transitive (if
x.compareTo(y) < 0andy.compareTo(z) < 0, thenx.compareTo(z) < 0must 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intcompareTo(T another)Compares this object to the specified object to determine their relative order.
-
-
-
Method Detail
-
compareTo
int compareTo(T another)
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.
-
-