From what I read, HashSet stores data in a unsorted manner. However I was given this question . (I don't want anyone to solve it)
Write a program to keep car details in a HashSet with sorted manner on the based of car name using comparator. Also calculate which car have maximum and minimum speed And average speed of all car.car class structure could be like.Also consider exception scenarios
(car is a class that has a element name)
I am confused now. Is it possible the question is slightly wrong? If so can anyone help me in figuring the correct question?
The question appears to be slightly wrong. It should be :
Write a program to keep car details in a
Set
with sorted manner on the based of car name using comparator. Also calculate which car have maximum and minimum speed And average speed of all car.car class structure could be like.Also consider exception scenariosBecause, only
TreeSet
has a constructor which acceptsComparator
. You cannot useComparator
withHashSet
.