This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList

 
vicky john
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vicky,

I'll move this post to our JiG(B) forum, which is more appropriate for this question.
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the data being inserted in the ArrayList?Can you show some code?
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three ways of iterating over any List:
 
Campbell Ritchie
Sheriff
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48642
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right, then. 3� ways
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic