Set or List
1 posts in topic
Flat View  Flat View

Posted By:   ChakhDe_India
Posted On:   Tuesday, June 3, 2008 10:37 PM


I am bit confsed about the use of Set and List, I know about differences set adn list have but i really do not understand one thing - people say that list contain duplicate data...set doesn't allow it. myquestion is if list allow duplicate data then your DB(data) is not good, meand redundant data then why don't u use set?

Please give some pointer? I need some example to understand this situation.

thanks in advance.

Re: Set or List

Posted By:   Stephen_McConnell  
Posted On:   Wednesday, June 4, 2008 10:44 AM

A List will allow you to put duplicate data into the List... yes. This is because the only control over what goes into the list (if you are using Generics) is the object Type of the list.

This doesn't mean your database is bad... You can have unique keys in the database that prevents duplicate data.

A List is just a container to hold ... well a List of things.

A Set is a specific type of collection that allows no duplicate. It does this by comparing 1) the object reference and 2) using the element1.equals(elemet2) method. If you haven't done a proper override of the equals method on you element, you might not get the results you want.

You database schema and indexing methods should prevent duplicates to the DB... Let the DB worry about that... It's MUCH faster than Java...

Stephen McConnell

About | Sitemap | Contact