This file contains hidden or 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
234 is the calling code for Nigeria | |
1 is the calling code for USA | |
233 is the calling code for Ghana |
This file contains hidden or 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
val currenciesMutableMap: MutableMap<String, String> = mutableMapOf("Naira" to "Nigeria", "Dollars" to "USA", "Pounds" to "UK") | |
println("Countries are ${currenciesMutableMap.values}") // Countries are [Nigeria, USA, UK] | |
println("Currencies are ${currenciesMutableMap.keys}") // Currencies are [Naira, Dollars, Pounds] | |
currenciesMutableMap.put("Cedi", "Ghana") | |
currenciesMutableMap.remove("Dollars") |
This file contains hidden or 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
print(currenciesMutableMap.get("Nigeria")) // will print Naira | |
print(currenciesMutableMap["Nigeria"]) // will print Naira |
This file contains hidden or 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
val personsHashMap: java.util.HashMap<Int, String> = hashMapOf(1 to "Chike", 2 to "John", 3 to "Emeka") | |
personsHashMap.put(4, "Chuka") | |
personsHashMap.remove(2) | |
print(personsHashMap[1]) // will print Chike |
This file contains hidden or 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
val postalCodesHashMap: java.util.LinkedHashMap<String, String> = | |
linkedMapOf("NG" to "Nigeria","AU" to "Australia","CA" to "Canada") | |
postalCodesHashMap.put("NA", "Namibia") | |
postalCodesHashMap.remove("AU") | |
postalCodesHashMap.get("CA") // Canada |
This file contains hidden or 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
val personsSortedMap: java.util.SortedMap<Int, String> = sortedMapOf(2 to "Chike", 1 to "John", 3 to "Emeka") | |
personsSortedMap.put(7, "Adam") | |
personsSortedMap.remove(3) |
This file contains hidden or 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
val stringList: List<String> = listOf("in", "the", "club") | |
print(stringList.last()) // will print "club" | |
// given a predicate | |
print(stringList.last{ it.length == 3}) // will print "the" | |
val intSet: Set<Int> = setOf(3, 5, 6, 6, 6, 3) | |
print(intSet.last()) // will print 3 |
This file contains hidden or 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
print(stringList.first()) // will print "in" | |
print(intSet.first()) // will print 3 |
This file contains hidden or 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
val intList: List<Int> = listOf(1, 3, 4) | |
print(intList.max()) // will print 4 | |
print(intSet.max()) // will print 6 |
This file contains hidden or 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
print(stringList.drop(2)) // will print "club" |