Scala Int Compare Method With Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala Program to demonstrate the 
// compare method of Int class
  
object GfG
   
    // Main Method
    def main(args:Array[String])
    {
       
        // Applying the method
        val v1 = (451).compare(145)
           
        // Displaying the output
        println(v1)
       
    }

chevron_right


Output:

1

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala Program to demonstrate the 
// compare method of Int class
  
object GfG
   
    // Main Method
    def main(args:Array[String])
    {
       
        // Applying the method
        val v1 = (121).compare(1478)
           
        // Displaying the output
        println(v1)
       
    }

chevron_right


Output:

-1



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : nidhi_biet

Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.