Groovy Quiz 18 | Lists | Part-2


Reference video | Groovy Playground


1 Point for every correct answer | Let’s Get Started

1.

Guess the output
(Can run and check code here – https://groovy-playground.appspot.com/)

def myList = [1,2,3,4,5]
myList.add(10)
myList<<20
print myList
 
 
 
 

2.

def myList = [1,2,3,4,5]
myList.add(3,33)
print myList
 
 

3.

def myList = [1,2,3,4,5]
myList.remove(3)
print myList
 
 
 

4.

def myList = [1,2,3,4,5]
myList + [10,20]
print myList
 
 

5.

def myList = [1,2,3,4,5]
myList = myList + [10,20]
print myList
 
 

6.

def myList = [1,2,3,4,5]
myList = myList.plus([50])
print myList
 
 
 

7.

def myList = [1,2,3,4,5]
myList = myList - [3,4]
myList = myList.minus([5])
print myList
 
 
 
 

8.

def myList = [1,2,3,4,5]
myList.pop()
print myList
 
 
 

9.

//Find match in a list

def myList = [1,2,3,4,5]
print myList.intersect([2,4,10,20])
 
 
 

10.

def myList = [1,2,3,4,5]
myList = myList.reverse()
print myList
 
 
 

5