I'm having an issue in groovy trying to figure out how to convert a single item to a list. I have an incoming variable params.contacts
, which could be a single value (e.g. 14) or it could be an array of values (e.g. 14, 15). I want to always turn it into a list. Previously, I was simply saying params.contacts.toList()
, but this code fails when it's a single item. It would take a value of 14 and divide it into a list of [1, 4].
Is there a simple, elegant way of handling this problem?