DEV Community

Coder
Coder

Posted on • Originally published at itscoderslife.wordpress.com on

1 1

Android-Kotlin Digest #3 – A gist of Collection types

Today in Kotlin, learnt about Arrays, Hashmaps, ArrayList, MutableList, MapOf, ArrayOf. Here is gist of things.

In Swift we have all the functionalities of Array in one place.

In here Kotlin we may need to use combination of Array and ArrayList.

Here are few Kotlin examples:

Array :

var myArray = Array<Int>(6){2}
for (element in myArray) {
println("Item - " + element)
}

for (index in 0..myArray.size - 1) {

println(myArray[index])

}

ArrayList :

var myArrayList = ArrayList<String>()
myArrayList.add("It's")
myArrayList.add("Coders")
myArrayList.add("Life")

if (myArrayList.contains("Coders"))

println("He's a rockstar!")

myArrayList.remove("Coders")

myArrayList.add("Dams")

//iterating through objects

for (names in myArrayList) {

println("Names:" + names)

}

HashMap : (Dictionary in Swift)

var hashmap = HashMap<String, String>()
hashmap.put("Mary", "Married")
hashmap.put("Paulo", "Married")
hashmap.put("John", "Single")

for (k in hashmap.keys)

println(hashmap.get(k))

Other Collection Utilities:

var myArrayList = listOf<String>("Me", "James", "Bonni", "Life")
var mutableList = mutableListOf<String>("Me", "They", "James")
var myHashmap = hashMapOf(1 to "Paulo", 2 to "James")

happyCoding();

Sentry mobile image

App store rankings love fast apps - mobile vitals can help you get there

Slow startup times, UI hangs, and frozen frames frustrate users—but they’re also fixable. Mobile Vitals help you measure and understand these performance issues so you can optimize your app’s speed and responsiveness. Learn how to use them to reduce friction and improve user experience.

Read full post →

Top comments (0)

Sentry growth stunted Image

If you are wasting time trying to track down the cause of a crash, it’s time for a better solution. Get your crash rates to zero (or close to zero as possible) with less time and effort.

Try Sentry for more visibility into crashes, better workflow tools, and customizable alerts and reporting.

Switch Tools

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay