Skip to content

Instantly share code, notes, and snippets.

View sajjadyousefnia's full-sized avatar
🤒
Out sick

Sajjad Yousefnia sajjadyousefnia

🤒
Out sick
View GitHub Profile
234 is the calling code for Nigeria
1 is the calling code for USA
233 is the calling code for Ghana
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")
print(currenciesMutableMap.get("Nigeria")) // will print Naira
print(currenciesMutableMap["Nigeria"]) // will print Naira
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
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
val personsSortedMap: java.util.SortedMap<Int, String> = sortedMapOf(2 to "Chike", 1 to "John", 3 to "Emeka")
personsSortedMap.put(7, "Adam")
personsSortedMap.remove(3)
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
print(stringList.first()) // will print "in"
print(intSet.first()) // will print 3
val intList: List<Int> = listOf(1, 3, 4)
print(intList.max()) // will print 4
print(intSet.max()) // will print 6
print(stringList.drop(2)) // will print "club"