Convert list (long) to list (string) in Grails2.4.3 (Groovy)
The post call gives the data in the form List<Long>
and now I have to convert it to List<String>
, so I used this approach for that:
deleteAvailablity.startDate.each {
startDateList.add(it.toString())
}
deleteAvailablity.startDate = startDateList
Is there a better approach than this one?
+3
source to share
2 answers
Use the Spread Operator
This simple construct should do the following:
assert [1l, 2l, 3l]*.toString() == ['1', '2', '3']
+7
source to share