Groovy web console

subscribe to the feed Subscribe
to this
site

List Operations

Published 1 month ago by MB with tags sort reverse remove combine flatten
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def list = [5, [6], [3,4], 1, 2]
      println "Size : " + list.size()
  def flat = list.flatten()
      println "Flatten: " + flat
      println "flat.size: " + flat.size()
  
      rev = flat.reverse()
      println "rev : "  + rev 
  
  def srt = flat.sort()
      println "srt : " + srt
      println "srt reverse : " + srt.reverse()
  
  def anotherList = [7, [9], [4,8], 6, 10]

  def comb = list + anotherList
      println "comb : " + comb
      comb = comb.flatten()
      println "Comb Flatten Sort: " + comb.sort()

  def uni = comb.unique()
      println "unique Comb Values : " + uni

  def rem = uni - [4,5]
      println "Remove: " + rem 
      println "desc order: " + rem.reverse()