Scala Int CompareTo Method With Examples
Last Updated :
18 May, 2021
compareTo is an int class method in Scala which is used to compare this with that operand. It is similar to the compare Method.
Syntax: (Given_Value1).compareTo(Given_Value2)
Returns: return -1 when Given_Value1 is less than Given_Value2. return 0 when both values are equal. return 1 when Given_Value1 is greater than Given_Value2.
Example 1:
Scala
object GfG
{
def main(args : Array[String])
{
val v 1 = ( 500 ).compareTo( 400 )
println(v 1 )
}
}
|
Example 2:
Scala
object GfG
{
def main(args : Array[String])
{
val v 1 = ( 200 ).compareTo( 700 )
println(v 1 )
}
}
|
Share your thoughts in the comments
Please Login to comment...