VO有如下属性:crtorg , crtorgname ,yearno,monthno,codevalues,orgno, province
ArrayList(docLists)存有从数据库查询的177个VO
有的VO中crtorg ,yearno,monthno是相同的
比如61000,2005,1的有3条
61001,2005,2的有4条
现在需要从中得到数据61000,2005,1和总和3
61001,2005,2和总和4
请问如何实现
ArrayList(docLists)存有从数据库查询的177个VO
有的VO中crtorg ,yearno,monthno是相同的
比如61000,2005,1的有3条
61001,2005,2的有4条
现在需要从中得到数据61000,2005,1和总和3
61001,2005,2和总和4
请问如何实现
VO如下,现在ArrayList(listA)在随后设置
public class A {
int m;
int n;
public int getN() {
return n;
} public void setM(int m) {
this.m = m;
} public void setN(int n) {
this.n = n;
} public int getM() {
return m;
}}import java.util.ArrayList;
import java.util.List;public class Untitled1 {
public Untitled1() {
}
public static void main(String[] args){
List listA = new ArrayList(); //原始集合
List listB = new ArrayList(); //获取的集合
A a1 = new A(); //给listA添加
a1.setM(1);
listA.add(a1); A a2 = new A();
a2.setM(1);
listA.add(a2); A a3 = new A();
a3.setM(1);
listA.add(a3); A a4 = new A();
a4.setM(2);
listA.add(a4);
现在得到的是1,3(个)
2,1(个)
import java.util.*;public class Map {
public Map() {
}
public static void main(String[] args){
HashMap map = new HashMap();
List listA = new ArrayList(); //原始集合
List listB = new ArrayList(); //获取的集合
for(int i=0;i<1;i++){
A a1=new A();
a1.setM(1);
listA.add(a1);
}
for(int j=0;j<1;j++){
A a2=new A();
a2.setM(2);
listA.add(a2);
}
for(int j=0;j<1;j++){
A a3=new A();
a3.setM(3);
listA.add(a3);
} int c=1;
if(listA.size()!=0){
A a=(A)listA.get(0);
map.put(new Integer(a.getM()),new Integer(1));
}
for (int i=1;i<listA.size();i++){
A a=(A)listA.get(i);
A formera=(A)listA.get(i-1);
if(a.getM()==formera.getM()){
c++;
map.put(new Integer(a.getM()),new Integer(c) );
}else{
c=1;
map.put(new Integer(formera.getM()),new Integer(c) );
}
}
System.out.println("1="+map.get(new Integer(1)));
System.out.println("2="+map.get(new Integer(2)));
System.out.println("3="+map.get(new Integer(3)));
}
}