Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a List (long) into List(String ) in Grails2.4.3 (Groovy)

Tags:

grails

groovy

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?

like image 493
abhaygarg12493 Avatar asked Jan 06 '15 13:01

abhaygarg12493


1 Answers

You can use collect:

def listOfLongs = [0L, 1L, 2L]
def listOfStrings = listOfLongs.collect { it.toString() }

assert listOfStrings == ["0", "1", "2"]
like image 52
Paweł Piecyk Avatar answered Oct 14 '22 09:10

Paweł Piecyk