File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes loading objects into arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "loading objects into arraylist" Watch "loading objects into arraylist" New topic
Author

loading objects into arraylist

rames tirrupur
Greenhorn

Joined: Jul 25, 2006
Posts: 13
Hi All,

I have a scenario where i need to add objects to arraylist based on some condition.

eg: After firing sql, i get the results with duplicate customer number.
I want to add the same customer numbers to one arraylist and add the different customer number to other arraylist. and finally add both the arraylist to hashmap.

How to do this?

Thanks,
rames
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

This is basic java, not servlet related. Please post to the correct forum next time

You know the HashMap class ?
You use put() and get(), then you can solve your problem.


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61204
    
  66

Moved to java in General (beginner).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
what do you mean by "same" customer number and "different" cutsomer number?

If by "same" you mean "unique" and by "different" you mean "duplicate" customer numbers., then the following code should achieve what you want.


[ July 27, 2006: Message edited by: Lynette Dawson ]

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if this answers the right question. This will make a map with key=customer number and value=a bunch of rows.

Is that close?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading objects into arraylist