File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Remove duplicate value from resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Remove duplicate value from resultset" Watch "Remove duplicate value from resultset" New topic

Remove duplicate value from resultset

khamhielle gabriel

Joined: Aug 15, 2011
Posts: 19

can somebody give me a hand on this:

i was trying to avoid printing duplicate data from the database

where in whenever i call from the database, most of the other values are just reprinted because there is one unique value.
what i need to do is to just print only what is unique on its given group.

Example of repeated values:

1234av Casie 5678
1234aw Shel 5762
1234aw Shel 0998
1234ax nica 9754

needed output :

1234av Casie 5678
1234aw Shel 5762 0998 ---* the unique value should be printed at the side rather than creating the whole set of line again.
1234ax nica 9754

sorry i'm really poor on loops please help me. thanks

and God Bless

ps: i was printing it on a text file
Gerald Lam

Joined: Aug 23, 2010
Posts: 6
Hm, I'm not sure if there's a better way to do it, but in my opinion, you could use a Map to store the values, so and check if there's a duplicate, if there is, get the value and append the new value to it.
For the key, you could combine both, for example, from the code you've given, 1234aw,Shel. And if you need to use the key, just split it with ",".
I agree. Here's the link:
subject: Remove duplicate value from resultset
It's not a secret anymore!