'How to get the maximum value of list in groovy?

Tried this code but it wont return the expected output. The list that i have doesnt have single quote.

def curlCmd = sh(script: "<some curl cmd POST>", returnStdout:true).trim()
def parsedResponse = readJSON text: curlCmd
def response = parsedResponse['fruit']
// Output of response is [apple123, apple124, apple125]
def maxValue = response.max() 

echo "maxValue: ${maxValue}"

Actual Output:

maxValue: []

Expected Output:

maxValue: [apple125]


Solution 1:[1]

This works fine:

def curlCmd = sh(script: "<some curl cmd POST>", returnStdout:true).trim()
def parsedResponse = readJSON text: curlCmd
def response = parsedResponse['fruit'] as ArrayList
// Output of response is [apple123, apple124, apple125]
def maxValue = Collections.max(response) 

echo "maxValue: ${maxValue}"

Output:

maxValue: apple125

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 monami