compare is an int class method in Scala which is used to compare this with that operand.
Syntax: (Given_Value1).compare(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:
object GfG
{
def main(args : Array[String])
{
val v 1 = ( 451 ).compare( 145 )
println(v 1 )
}
}
|
Example 2:
object GfG
{
def main(args : Array[String])
{
val v 1 = ( 121 ).compare( 1478 )
println(v 1 )
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
30 Oct, 2019
Like Article
Save Article