Convert Typed List in Groovy to String List

I'm trying to change a typed list into a string list. I'm using the AWS SDK to get a list of PackageVersionResponse objects and I want to create a String list of the version method:

def client = AWSCodeArtifactClientBuilder.standard()
  .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
def lpm = ListPackageVersionsRequest().builder(domain)
def pvs = client.ListPackageVersions(params)
// change pvs into String list of return value of version method

In node I'd do something like => pv.version()) and get a String array of versions, but I'm not sure what the equivalent is in Groovy / Java


  • Should just be

    def pvs = client.listPackageVersions(params).versions.collect { it.version }

    Or using the spread operator

    def pvs = client.listPackageVersions(params).versions*.version

    (from tracing the javadoc for the client method, the ListPackageVersionsResult object and the getVersion method inside the PackageVersionSummary class)