on 05-03-2007 9:49 AM
i have a beanList
which add some Object------outMail,outMailAck,outMailDetails
ArrayList beanList=new ArrayList();
beanList.add(outMail);
beanList.add(outMailDetails);
beanList.add(outMailAck);
sendMail(beanList);
sendMail(ArrayList beanList){
OutMailBean outMailBean = (OutMailBean) beanList.get(0);
OutMailDetailsBean outMailDetailBean =(OutMailDetailsBean) beanList.get(1);
OutMailAckBean ackBean = (OutMailAckBean) beanList.get(2);
//how can i loop the ackBean(); if there is more than 1
for(Iterator it=ackBean.get(1); it.hasNext();){ //ackBean.get(1).iterator()
OutMailAckBean outMailAck=(OutMailAckBean)it.next();
}
}
Hi,
1) get the size of ackBean, int sizeLIst = ackBean.size();
2)set a for loop as:
for(int i =0 ; i<= sizeList;i++)
{
//here you can access the elements of array
Iterator it=ackBean.get(i); //check we are fetching i'th element of arraylist
//do the processing you want ...
}
hope it helps
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yzme,
So you know that starting from index 2 all elements of list are OutMailAckBean. Then
sendMail(final ArrayList beanList){
final OutMailBean outMailBean = (OutMailBean) beanList.get(0);
final OutMailDetailsBean outMailDetailBean =(OutMailDetailsBean) beanList.get(1);
/* Commented out -- all ack accessed in loop below
OutMailAckBean ackBean = (OutMailAckBean) beanList.get(2);
*/
for (final Iterator it = beanList.sublist(2, beanList.size()).iterator; it.hasNext(); ) {
final OutMailAckBean outMailAck=(OutMailAckBean)it.next();
}
}
In plain english: get sublist of elements from 2 (inclusive) till list size (exclusive) and iterate over this sublist.
Valery Silaev
SaM Solutions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.