• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vicky,

I'll move this post to our JiG(B) forum, which is more appropriate for this question.
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the data being inserted in the ArrayList?Can you show some code?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are three ways of iterating over any List:
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right, then. 3� ways
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic