Compare version strings in groovy

后端 未结 11 1930
耶瑟儿~
耶瑟儿~ 2020-11-30 09:50

Hey I have created a Groovy script that will extract the version numbers of some folder. I would then like to compare the version numbers and select the highest.

I g

11条回答
  •  暖寄归人
    2020-11-30 10:48

    Mine is the shortest! lol )

    versions = versions.sort {a, b ->
      def a1 = a.tokenize('.')*.toInteger(), b1 = b.tokenize('.')*.toInteger()
      for (i in 0..<[a1.size(), b1.size()].min()) 
        if (a1[i] != b1[i]) return a1[i] <=> b1[i]
      0
    }
    

提交回复
热议问题