hashmap 获取带名字的集合
通过数据库获取一个集合list后,想将集合中的一个字段放进一个集合中,可以通过hashmap来获取,如下代码获取字段为dateCount的集合
String[] arr=new String[list.size()];
IdentityHashMap<String,Object> identityHashMap =new IdentityHashMap<>();
for (SysOperLog item : list) {
identityHashMap.put(new String("dateCount"),item.getDateCount());
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("dateCount",identityHashMap);
数组获取一个字段的集合(不带名字)
int[] arr = new int[list.size()];
int count = 0;
for (SysOperLog item : list) {
arr[count] = item.getIpCountBefore();
count++;
}