Reputation: 1605
Post call gives data in the form of List<Long>
and now I have to convert it into List<String>
, so I used this approach for it:
deleteAvailablity.startDate.each {
startDateList.add(it.toString())
}
deleteAvailablity.startDate = startDateList
Is there any better approach than this?
Upvotes: 7
Views: 9693
Reputation: 84756
Use the Spread Operator
This simple construct should do the job:
assert [1l, 2l, 3l]*.toString() == ['1', '2', '3']
Upvotes: 9
Reputation: 2789
You can use collect
:
def listOfLongs = [0L, 1L, 2L]
def listOfStrings = listOfLongs.collect { it.toString() }
assert listOfStrings == ["0", "1", "2"]
Upvotes: 12