Search code examples
grailsarraylistgroovy

How to replace a String from Arraylist without iteration In Grails?


I want to replace some Words in String without using any loops.

 def tagList= []
 def tags= []
 tags.each { tag ->
   def newString = tag.replaceAll("sample", "")
   tagList.add(newString)
 }

Solution

  • This is the goodness of groovy you can directly replace string without iterating the List.

    please try below code

     def tagList= []
     tagList = tags.join(',').replaceAll('sample','').split(',')