Question
How can I use Comparator while using an Iterator? (Java) For example: Consider I created a collection (not any of the defined ones in existing
How can I use Comparator while using an Iterator? (Java)
For example:
Consider I created a collection (not any of the defined ones in existing java libraries like, java.util.ArrayList, java.util.List, etc..). it's known as a SortedArrayCollection col; It holds Book objects, and I want to sort them by "title". Also, I have created a method that returns an Iterator within this collection.
Now consider I created a class that implements the Comparator interface and sorts them by title, lets call that TitleComparator.
In my test Driver lets say that I used an Iterator to iterate
Iterator it = col.iterate();
How do I sort with the comparator? Without using collections.sort() or Arrays.sort(),
(2796) 12:55 PM Eile Edit View Navigate Source Refactor Bun Debug Profile Team Iools Window Help Search (CErt+ p9 C"Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started