阅读背景:

根据java中的键对地图的值进行排序

来源:互联网 

Here is my code:

这是我的代码:

/* Returns a Map that stores a contact name as a key and a list of messages from that contact
as a value. If a message has no associated contact, it should not appear in the Map. Must 
not change messages field. Must call filter with an anonymous inner class in the method body. */
public Map<String, List<Message>> sortMessagesByContact() {
    Map<String, List<Message>> map = new HashMap<>();
    List<Message> filtered = new ArrayList<>();

    Predicate<Message> p = new Predicate<>() {
        @Override
        public boolean test(Message t) {
            return t.getContact().isPresent();
        }
    }; for (Message mg : messages) {
        if (p.test(mg)) {
            map.put(mg.getContact().get(), messages);
        }
    }
    return map;
}
/* Returns a Map t



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: