I'm a Comp-Sci Student. I'm working on an assignment in which I have to make a Table class that has a "Key"(Type String) and "Value"(Type Object) property. Sort of like a mini database. Pretty much if I use a get method using "Key" as the parameter it will return the "Value" property.
It came to my mind that I should use a multi-dimensional array of type Object with the first element of a row being the "Key" and the second element being the "Value".
I was wondering if this is bad practice/ or if there is an obvious and more convenient way of going about this.
What I decided to do since hash-maps were dis-allowed: I made 2 separate ArrayLists. One will store Keys the other will store Values. Their indexes will correspond. So the index of a Key passed into a getMethod will return the value of the Value ArrayList at the index of Key since they correspond.
Thanks to everyone who answered. My account is fairly new so I don't have many privileges yet, such as voting. This was a really great preview of how great this community probably is.
Map<K, T>-- that's exactly what they're for.Mapimplementation, such asHashMap