This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes filter the collection in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "filter the collection in java" Watch "filter the collection in java" New topic
Author

filter the collection in java

jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
I have a collection return from DB like bellow, i want to filter the collection so the end result will only has 1 unique name and their concatinate of bank name that they have.

Any suggestion would really appreciated.
Thanks



Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29219
    
135

You've done the first step - define clearly what you wanted. Now the next step is to get started. Can you explain (in Java code or pseudocode or English) how you coudl use a loop to do this? For example:
1) look at the first entry
2) write down the following from it
3) look at the second entry
4) compare it to what is written down. if X matches, do Y. otherwise, do Z

Do post what you come up with here so we can hint at the next step.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
jay lai
Ranch Hand

Joined: Apr 04, 2002
Posts: 180
Jeanne Boyarsky wrote:You've done the first step - define clearly what you wanted. Now the next step is to get started. Can you explain (in Java code or pseudocode or English) how you coudl use a loop to do this? For example:
1) look at the first entry
2) write down the following from it
3) look at the second entry
4) compare it to what is written down. if X matches, do Y. otherwise, do Z

Do post what you come up with here so we can hint at the next step.


This is what I have so far, but still not sure how to get the appending works properly


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7029
    
  16

jay lai wrote:I have a collection return from DB like bellow, i want to filter the collection so the end result will only has 1 unique name and their concatinate of bank name that they have.

I hate to say, but you seem to be looking at this as just a bunch of Strings rather than what they represent. You might want to check out the StringsAreBad page while you're at it.

What I see when I look at that data is two types of data: Banks and Customers.

A Bank has a name, and a Customer has a name and an address. What I also see is that the same Customer can be a member of more than one Bank.

So, why not create Java classes that reflect that? eg:I leave the rest up to you, but if you create objects that make sense, I think you'll find this "filtering" operation much easier. You'll also have classes that you can reuse for other things.

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter the collection in java
 
Similar Threads
question about jess templates
Appending two Multidimensional Arrays together
plz reply as soon as possible
Can Arrays be treated as DB tables?
User-defined objects in collections