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 sourceKey = ["Winnipeg","Patriots","Cowboys"]

if(sourceKey == "Cowboys") {
        print "Test"
    }   
     
if (sourceKey == "Patriots") {
        print "Test Panels"
    } 
if (sourceKey == "Winnipeg, Patriots, Cowboys") {
        print "Correct"
    }
else {
        print "Good code"
    }


/*def stringName = 'Testing, testing 00, testing'


def stringNew = stringName.tokenize(",")

def nwName = [] as Set

stringName.each {it
nwName << stringNew[0]
}
print nwName*/

/*def stringName = 'Testing, testing 00, testing'


/*def stringNew = stringName.tokenize(",")

/*def nwName = [] as Set

/*stringNew.each {it
/*    nwName << stringNew[0]
/*} 
/*print nwName


/*maidenName = "Patient"
/*aliasName = "One"

/*newName = [maidenName, aliasName]

print newName*/

/*(1..7).each {
    print("Number {it}") /*{it} Is code to iterate through the list it references....
}*/
/*['Dog', 'Cat', 'Horse'].each {animalName ->
    print "${animalName}" /*The point of this code is to show how I didn't use {it} as a variable to the list, I assigned a variable on the fly-setting it
}*/ 
['Dog','Cat','Horse '].eachWithIndex {animalName, index ->
    print " ${index+1}. Animal:${animalName}"
} /*Here I'm setting the temp variable for the index, also when you need to output more than one value, write in code that increments on the temp variable that I'm using as the temp variable for the index*/

/* In GroovyScript, elif is not within it's logic, I'd need to use multiple IF statements*/
newList = [0,1,2,3]
newList.add(4)

if (newList == "") { 
print(newList)
    } 
if (newList == 2) {
print("Dos")    
}
else
{
print("No Data")    
    }


Mothers_Maiden = ["Test", "Testing", "Test", "Testing", "Test", "Testing"]

newMaiden = Mothers_Maiden as Set

print newMaiden

testName = ["One","One","Two","Two"] as Set
print testName

testIng = ["Three","Three","Four","Four"] .toSet()
print testIng



def kList = []  

def oList = [1,2,3,4,4]

kList = oList /*Here I could select an element of the list by using an INDEX []..I could use to Set here as well*/ 
print kList  /*Here I've used as Set to ensure that I get unique-non duplicated values.. I could use INDEX as well*/







Advertisements
Loading...

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