-
-
Save pradhuman7d1/a8fba25d73014889767500d74531fdb2 to your computer and use it in GitHub Desktop.
Kotlin Collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. What are some examples of collections ? | |
A. Lists, Arrays, Maps, Sets are collections. | |
Q. How many types of lists are there? | |
A. Lists are of two types : Mutable Lists and Immutable Lists. | |
Q. What is a map? | |
A. A map is a collection that holds and key and a value pair. | |
Q. What datatypes can be stored in collections? | |
A. You can store any type of variables in the collections. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q. How to create a mutable list? | |
a) var list : mutableListOf<Any> = mutableListOf(1,2,3,4) | |
b) var list : MutableListOf<Any> = mutableListOf(1,2,3,4) | |
c) var list : MutableListOf<Any> = MutableListOf(1,2,3,4) | |
A. b) var list : MutableListOf<Any> = mutableListOf(1,2,3,4) | |
Q. How to delete an element e from a list numList? | |
a) numList.clear(e) | |
b) numList.removeAt(e) | |
c) numList.remove(e) | |
A. c) numList.remove(e) | |
Q. How to add a key value pair (key, val) in a map? | |
a) map.put(key to val) | |
b) map.put(key, val) | |
c) map.put(val, key) | |
d) map.put(val to key) | |
A. b) map.put(key, val) | |
Q. What are x and y if we traverse a map? | |
for((x, y) in map){ | |
} | |
a) x is key, y is val | |
b) x is val, y is key | |
A. a) x is key, y is val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment