# 如何求ArrayList中各元素出现次数？

0

bwin | 初学一级 | 园豆：116

0

DataTable dt = e.Result as DataTable;
DataRow [] dr = dt.Select("","xftime asc");

List<myelem> al = new List<myelem>();
List<myelem_result> al_result = new List<myelem_result>();

foreach (DataRow r in dr)
{
myelem me = new myelem();
me.pub_name = r[5].ToString().Trim();

me.pub_riqi = Convert.ToDateTime(r[2]).ToString("yyyy-MM-dd");
me.pub_int = 1;

dataitem d = new dataitem();
d.pub_time = Convert.ToDateTime(r[2]).ToString("HH:mm");
d.pub_station = r[7].ToString();

me.pub_item = d;

}

int flag = 1;
for (int i = 0; i < al.Count; i++)
{
List<dataitem> ld = new List<dataitem>();
myelem_result me_result = new myelem_result();
me_result.pub_riqi = al[i].pub_riqi;
me_result.pub_name = al[i].pub_name;

dataitem d2 = new dataitem();
d2.pub_time = al[i].pub_item.pub_time;
d2.pub_station = al[i].pub_item.pub_station;
d2 = null;
me_result.pub_list_item = ld;

for (int j = i + 1; j < al.Count; j++)
{
if (i + 1 < al.Count)
{
if (al[i].pub_riqi == al[j].pub_riqi)
{
flag++;

dataitem d1 = new dataitem();
d1.pub_time = al[j].pub_item.pub_time;
d1.pub_station = al[j].pub_item.pub_station;
d1 = null;

al.RemoveAt(j);
j--;
}
}
}
me_result.pub_int = flag;
me_result = null;
flag = 1;
}

bwin | 初学一级 |园豆：116 | 2016-03-16 09:47

0

5207 | 园豆：9 (初学一级) | 2016-02-24 11:24
0

jackccc | 园豆：1341 (小虾三级) | 2016-02-24 11:33
0

group by

0

2

var list=new{张三, 李四, 张三, 李四, 张三}

list.groupby(m=>m).select(m=>{m,m.count})

0

java中的Collections.frequency(Collection Object o)：返回指定集合中指定对象出现的次数

import java.util.*;

public class ArrayListTest {

public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
int[] array = {1, 12, 43, 12, 13, 12, 43};
for (int i : array) {
}
System.out.println(Collections.frequency(list, new Integer(1)));
System.out.println(Collections.frequency(list, new Integer(12)));
System.out.println(Collections.frequency(list, new Integer(43)));
System.out.println(Collections.frequency(list, new Integer(13)));
}
}

no-npe | 园豆：387 (菜鸟二级) | 2016-02-24 15:50

您需要登录以后才能回答，未注册用户请先注册