I have a Post class which contains 3 properties: userId
, userName
, postId
.
Every post generates a unique id(String) in the database, so I save it in a HashMap, where the Key is the unique post id, and the value is the Post, like so:
HashMap<String, Post> posts = new HashMap<>();
posts.put(postId, new Post(userId, userName, postId)).
And now I want to find all the posts in the map, with a specific userId
. How to do that?