假设,我有一个数组列表:
catalog id--->901
Catalog name --->series277
catalog id--->901
Catalog name --->series277
catalog id--->545
Catalog name --->series285
catalog id--->545
Catalog name --->series285
catalog id--->545
Catalog name --->series285
catalog id--->546
Catalog name --->series685
catalog id--->546
Catalog name --->series685
catalog id--->40962
Catalog name --->series19348
catalog id--->40962
Catalog name --->series19348
catalog id--->40962
Catalog name --->series19348
catalog id--->40962
从这个列表中,我想找到如下所示的出现次数。
catalog id--->901 -- 2
catalog id--->545 -- 3
catalog id--->546 -- 2
catalog id--->40962 -- 4
我的目标是,根据id我想创建一个循环以进一步迭代的出现次数。
请找到我创建 Arraylist 的 java 代码
List<Catalog> catalogList2 = new ArrayList<Catalog>();
for (SearchHit hit1 : searchHits2)
{
sourceAsMap2 = hit1.getSourceAsMap();
catalog2 = new Catalog();
catalog2.setId(String.valueOf(sourceAsMap2.get("catalog_id")));
catalog2.setCatalog_name(String.valueOf(sourceAsMap2.get("catalog_name")));
catalogList2.add(catalog2);
}
更新
尝试实现以下案例:
for(int i=0;i<catalogList2.size();i++) {
// want to find the number of occurances for catalog.getId()
//Then i want to create a loop based on the number of occurances of catalog id
for(int i=0;i<catalog_id_occurances.size;i++)
{
//Have to do something.
}
}
翻过高山走不出你
相关分类