1
votes

After clearing, when adding values to list this is not initializing/emptying the list, however, taking the previous list data.

Groovy code as follows:

--Groovy Test Script: 
    def list_2 = []
    list_2.clear()
    log.info list_2
    log.info list_2.add("a1") //adding 1st value
    log.info list_2.add("z2") //adding 2nd value
    log.info list_2.add("x3") //adding 3rd value
    log.info list_2.add("d4") //adding 4th value
    log.info list_2
    log.info list_2.sort()

https://community.smartbear.com/t5/SoapUI-Open-Source/how-does-LIST-work-in-SOAPUI-Groovy/m-p/152923

So here how come both sorted and unsorted list values are same?

1

1 Answers

1
votes

If you want list2 to be sorted after calling sort() on it, you need to pass an argument telling it to modify the list in place.

list2.sort(true)

Otherwise, sort() returns a new list that is sorted.

sortedList2 = list2.sort()