Groovy - How to compare the string?

后端 未结 7 1670
醉话见心
醉话见心 2021-02-04 23:03

how to compare the string which is passed as a parameter

the following method is not working.

 String str = \"saveMe\"

 compareString(str)

 def         


        
7条回答
  •  情深已故
    2021-02-04 23:28

    The shortest way (will print "not same" because String comparison is case sensitive):

    def compareString = {
       it == "india" ? "same" : "not same"
    }    
    
    compareString("India")
    

提交回复
热议问题