Groovy Quiz 17 | Lists | Part 1


Reference video | Groovy Playground


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

1.

Is the below information True of False

List in Groovy

syntax – [obj1, obj2, …]

[1,2,3,4] – list of integers

[“Groovy”, “Automation”, “Raghav”] – list of Strings

[1,2,[‘A’, ‘B’],4,5] – Nested list

[1,2,”Groovy”, 2.2] – Object list OR Heterogenous list

[] – Empty list

 

 
 

2.

Guess the output

def numbers = [1,2,3,4,5]
print numbers[2]
 
 
 

3.

def numbers = [1,2,3,4,5]
print numbers.get(3)
 
 
 

4.

//heterogenous list OR list of objects

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList[3][2]
 
 
 

5.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList.get(3).get(1)
 
 
 

6.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList[1..2]
 
 
 

7.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList[5,3]
 
 
 

8.

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

9.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]

print myList[3].contains("Groovy")

 

 
 

10.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList.size()
 
 
 
 

11.

def myList = [1,2,3,['A', 'B', "Groovy"],4,5]
print myList[3].size()
 
 
 

9