File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

loading objects into arraylist

rames tirrupur

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?

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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

Joined: Jan 10, 2002
Posts: 63839

Moved to java in General (beginner).

[Asking smart questions] [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:
subject: loading objects into arraylist
It's not a secret anymore!