Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
Created November 26, 2021 12:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pradhuman7d1/a8fba25d73014889767500d74531fdb2 to your computer and use it in GitHub Desktop.
Save pradhuman7d1/a8fba25d73014889767500d74531fdb2 to your computer and use it in GitHub Desktop.
Kotlin Collections
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.
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