Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Groovy Online

/*def string = 'California, Oklahoma, Texas, New York, New York'
string.split(",")
string.each {
    it -> print it /*it represents the elements in the list; it's like the temporary variable I use in Python.. It can be any temp Variable name. It doesn't have to be 'it'
}*/
 
/*string.each { it ->       *** .each {it ->}  this iterates through objects*** 
    print it
}*/
 
/*string.eachWithIndex { idx, it ->      
    print "Index #{idx}:${it} "
} 
def newList = [] as Set

newList << string

print newList*/

(1..3).each {
    print "Number:${it} " /*I aded a space at the end within the sting to allow space fpr the results for the next result for iterator{it}*/
}

/*def name = ['One','Two','Two','Three'].toSet().asSynchronized() /*.toSet() outputs unique values....asSynchronized, arranges the data by order of index position */

/*name.eachWithIndex{      /*Variable name.each within the list abave and with index*/
    /*it, idx -> print " ${idx}:${it} "*/  /*HERE...BEGIN with the temp variables: temp variable for the elements using {it}; temp variable for INDEX{idx}.....but....in my output or print statement, I code index variable first, then the temp variable for the elements
}*/
/*Also, within the print statement "space..allows space between each iteration. Each time the logic iterates trhough the list, if there isn't a space at the begining of the string...the output will position the beginning of the second output against the prior iteration's output....so I needed to lead off with a space. The logic in the website isn't coded that way, but in my console it works this way.... I can test that output in DPT. */

/*def alias = ["Joe","James; Joe","James Joe",";","James"].toSet() 
def first = ["Joe"]
def last =  ["James"]
def maiden = [] as Set

maidenName = alias

print alias[0] + alias[3] /*I entered the index [2]=result [;] this is bc .toSet() is making the values, "James; Joe" and "James Joe", the same index because it's a duplicate. Althought the ; is in the first of the set, WHEN IT PRINTS OUT, the output would remove the ; so considering that, the results would be the same in terms of output ....the index position counts those two values as base 1 index and the ";"  base index and "James" as base 3 index...if those two values were the same values, the index count would count each index.*/

/*print nameLast*/
 
/*def empty = ['Color':'Blue','Name':'Smurf']
empty << ['altName':'Test']  /*Here I've added a new key and value to a mapping string and shifting it to string
    print empty            

personDetails = ['Name':'Bobby','Age':32,'Dept':'Accounting']
    print " Name: ${personDetails.name}"
    print " Age: ${personDetails.Age}"
 
personDetails = ['name':'Bobby','Age':32,'Dept':'Accounting']
    print " Name:${personDetails.name} " + " " + " Age:${personDetails.Age}"
    print " Age:${personDetails.Age}"*/ /*Here I'm using the key and values as a getter with the Key and setter, while printing, for the key and value of the variable. REMEMBER if I want to add spacing, I could add it within the mappings in the string and concatenate parathesis and / or add spacing between the quotes or double quotes from the variableName in the string "variableName" versus  " variableName"*/
 
 /*I don't need the parathesis, bc I'm retrieving from a map*/ 
 
 nameList = ["Pedro","Hydra","Iron Man"]  /*Here's the list of items*/
 
 def wordWrap = nameList.collectEntries{ [(it):it.length() 
   ]
 }
 print wordWrap

/*def medList = {'Patient':01}
def newList = [:]

oldList = [{"Cold":1, "Name":{"nameFirst":"Bob"}}]*/

def medList = ['Patient':322] /* IN GROOVY....I use [] Brackets for Mapping..  {} to define an object*/ 

print medList 

def tbl = ['Test':01]
def tbl1 = ['Testing':02]
def newTbl = tbl + tbl1
print newTbl








    

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.