Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Sorting the Collection(java.util.Collection) of Elements

Thread view: 
Pradeep - 24 Jan 2007 03:45 GMT
Hi EveryBody,

Suppose that a collection(Java.util.Collection) contains some number of
elements and I have to iterate through the collection by comparing each
element in the collection with each other element so that no 2 elements
should be same...(Note: No two same elements having the same index
position in the collection shouldn't be eligible for comparison)...If
any one of u have any Idea so please Let Me know that..

Thanks& Regards,
Venkata Pradeep K.
Lew - 24 Jan 2007 04:35 GMT
> Suppose that a collection(Java.util.Collection [sic]) contains some number of
> elements and I have to iterate through the collection by comparing each
> element in the collection with each other element so that no 2 elements
> should be same...(Note: No two same elements having the same index
> position in the collection shouldn't be eligible for comparison)...If
> any one of u have any Idea so please Let Me know that..

I strongly suggest that you read the java.util (note: lower-case 'j') docs:
<http://java.sun.com/javase/6/docs/api/java/util/package-summary.html>

This question has been coming up a lot lately. If this is homework you might
need to understand how to make such a collection. If that is the case, the
correct way to go about doing the homework is not to provide a canned answer
that you don't fully understand, but to think the problem through.

Try first progrmming with a pen[cil] and paper. Think through the questions of
your problem in detail. For example:

If you have to iterate through the collection (is that really the requirement,
or can you check at the insert attempt?), what does that mean? What is
required at each loop of the iteration? What does it mean to "compare each
element in the collection"? Does this require, say, nesting another loop
inside, or is there another way? What do the API docs have to say? What are
the initial conditions: do you only know that there is a Collection, or can
you restrict it to some subtype? If you can, then what subtype would help?
WHat are the differences between different Collections, or even different
implementations of the same Collection (such as the many flavors of List)?

As you break down the problem into teeny, tiny little steps it will become
clearer how to represent those steps in a program.

- Lew
Patricia Shanahan - 24 Jan 2007 14:33 GMT
> Hi EveryBody,
>
[quoted text clipped - 4 lines]
> position in the collection shouldn't be eligible for comparison)...If
> any one of u have any Idea so please Let Me know that..

Why not just create a HashSet with the elements?

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.