Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java HashMap indexed on 2 keys

I want to create a HashMap in java for users with preferences. This would be easy to do in a database, but unfortunately I can't use a database. What I need is a way to find a user by name in the HashMap, and to find all the users with a certain interest (e.g. golf). If I delete a user, then all their interests should be deleted.

Anyone know a nice way to make this data structure?

like image 980
Marius Avatar asked Nov 26 '22 21:11

Marius


1 Answers

I would suggest you create your own data structure for holding the information. Inside that class you could have two HashMaps storing the relevant information. Then write your own methods to insert and delete a user.

This way you have control over the insert/delete-operations while being able to query each attribute separately.

like image 154
B.E. Avatar answered Dec 15 '22 05:12

B.E.