im a little stuck, i have a mutable map with Names...
# getting-started
m
im a little stuck, i have a mutable map with Names as a key and address's as a value, is it possible to "get" the key and value at any given index. For example, if i wanted to know the 6th in the map
d
Usually maps do not specify an order, and if they do (e.g.
LinkedHashMap
) access to the n-th element is usually quite slow. This is probably not a good idea to do 😉
👍 1
m
LinkedHashMap’s get is O(1) so that’s not an issue thankfully!
d
get
is, yes. But "find me the 6th element" is O(n)
👍 1
m
Ah yes, you’re right
d
But that performance does not even matter, unless your map is quite big. I just think it's a bit of a code smell.
👍 1
m
@mcscruff Maybe you would be better off with a class containing a name and an address, and then store them in a list?
m
im actually looking at a class now, just working out how to use it correctly
👍 1
i got it working, a class is a much better way to do it.