| Author |
ArrayList
|
vicky john
Greenhorn
Joined: Mar 23, 2008
Posts: 13
|
|
Hi, I'm having a method which will return total number of parts and corresponding warehouse names. I've declared return type as an Arraylist. Now, how can i retrieve both values by iterating this Arraylist?? Any help would be greately appreciated. Thanks in advance, vasavi.
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8147
|
|
Vicky, I'll move this post to our JiG(B) forum, which is more appropriate for this question.
|
[My Blog] [JavaRanch Journal]
|
 |
Manuel Leiria
Ranch Hand
Joined: Jul 13, 2007
Posts: 171
|
|
|
How is the data being inserted in the ArrayList?Can you show some code?
|
Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
There are three ways of iterating over any List:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Originally posted by Rob Prime: There are three ways of iterating over any List:
You have forgotten the 4th way There are bound to be more ways, eg while loop and i++ inside the loop, but these are the well-known standard ways to do it. [ May 12, 2008: Message edited by: Campbell Ritchie ]
|
 |
vicky john
Greenhorn
Joined: Mar 23, 2008
Posts: 13
|
|
This is my query in DAO: SQL_QUERY ="select count(parts.partNum),whse.whseId from CPartsVO parts,CInventoriesVO inv,CWarehouses whse where parts.custId = " + custId +"and inv.parst =parts.partID and whse.whseId = inv.wareHouseCD and inv.quantity > 0 GROUP BY whse.whseId"; returns result as : count(parts.partNum) | Whse.whseId ----------------------------------- 15 | ABC 10 | XYZ etc., From the DAO method, i'll return Arraylist to this manager bean. Now, from the Bean i want to retrieve these two arraylist values. in ManagerBean :: can i try to retrieve those two values like below? or is there any other way to get it?? please suggest.. itrPatList = list.iterator(); if(itrPatList != null) { while(itrPatList.hasNext()) { Object obj = (Object)itrPatList.next();
|
 |
Manuel Leiria
Ranch Hand
Joined: Jul 13, 2007
Posts: 171
|
|
Suppose you have a view object like this: and, at some point in your DAO class Now, in the managed bean, just iterate to get the objects: [ May 13, 2008: Message edited by: Manuel Leiria ]
|
 |
vicky john
Greenhorn
Joined: Mar 23, 2008
Posts: 13
|
|
Hi, Thanks for your suggestions. actually i don't have any VO or POJO classes which are having the properties of whatever i retrieve from my query in DAO. So i can't iterate it. I could solve the problem by using the Hash map where i'm passing one int value as a key and corresponding value as value and be able to retrieve both from my manager bean. Thanks alot once again
|
 |
Manuel Leiria
Ranch Hand
Joined: Jul 13, 2007
Posts: 171
|
|
Originally posted by vicky john: Hi, Thanks for your suggestions. actually i don't have any VO or POJO classes which are having the properties of whatever i retrieve from my query in DAO. So i can't iterate it. I could solve the problem by using the Hash map where i'm passing one int value as a key and corresponding value as value and be able to retrieve both from my manager bean. Thanks alot once again
Yes you could but what if two equal counts appear?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Originally posted by Campbell Ritchie: You have forgotten the 4th way There are bound to be more ways, eg while loop and i++ inside the loop, but these are the well-known standard ways to do it. [ May 12, 2008: Message edited by: Campbell Ritchie ]
To me that one is equal to the for loop version.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
All right, then. 3� ways
|
 |
 |
|
|
subject: ArrayList
|
|
|