【发布时间】:2015-03-20 22:38:19
【问题描述】:
在我的班级Feeds 中,我和其他成员有一个名为“Date”的成员变量,它属于String 类型。我有一个ArrayList 的Feeds 对象。我想找到具有相同日期字符串的对象的出现。然后可以将出现的次数放入 HashMap 中,其中包含 String 作为键的日期和作为值的出现次数。
类似的东西:
List<Feeds> m_feeds = new ArrayList<Feeds>();
//add all feeds objects
m_feeds.add(...);
int occurrences = 0;
HashMap<String, Integer> repeatedDatabase = new HashMap<String, Integer>();
for (Feeds f : m_feeds){
occurrences = Collections.frequency(m_feeds, f.date);
// i know this method compares objects but i want to know how
// only a single variable can be done
repeatedDatabase.put(f.date, occurrences);
}
【问题讨论】:
标签: java arraylist collections hashmap