Reader small image

You're reading from  Android Programming with Kotlin for Beginners

Product typeBook
Published inApr 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789615401
Edition1st Edition
Languages
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

Hashmaps


Kotlin HashMaps are interesting; they are a type of cousin to ArrayList. They encapsulate useful data storage techniques that would otherwise be quite technical for us to code successfully ourselves. It is worth looking at HashMap before getting back to the Note to self app.

Suppose that we want to store the data of lots of characters from a role-playing game and each different character is represented by an object of the Character type.

We could use some of the Kotlin tools that we already know about, such as arrays or ArrayList. However, with HashMap, we can give a unique key or identifier to each Character object, and access any such object using that same key or identifier.

Note

The term "hash" comes from the process of turning our chosen key or identifier into something used internally by the HashMap class. The process is called hashing.

Any of our Character instances can then be accessed with our chosen key or identifier. A good candidate for a key or identifier in the Character...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android Programming with Kotlin for Beginners
Published in: Apr 2019Publisher: PacktISBN-13: 9781789615401

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton