Reputation: 774
I have a dataset, and I'm not sure which type of List or Map to use in Java. Following is a sample dataset. There are 2 columns, Users and Errors.
A user can be repeated. Errors are random and there won't be any duplicates.
Users Errors
User A Error 1
User B Error 2
User A Error 3
User C Error 4
and I should be able to use the list to get all errors per user at the end.
I tried a hashmap, but it only retrieves the last entry for user.
Thanks in advance.
Upvotes: 1
Views: 36
Reputation: 27496
You can use Map of String to List. Depending on java version you might need to do manual checks if given key exists (in such case add the error) or doesn't (create list and add a single error)
Upvotes: 0
Reputation: 393956
You can use a HashMap<User,List<Error>
(not sure if there are User
and Error
classes or if they are represented by Strings or some numeric type, but you get the idea).
This will make it easy to obtain the List
of all errors for a given user.
Upvotes: 4