Exercises
You may not have noticed directly, but we’ve been longing for this! We can finally add collections and generics to the applications of our apps. Life will get easier. Let’s look at some exercises:
- Our park has an assortment of dinosaurs and their related data. Implement a
Listinterface that stores a custom dinosaur class. - We need to ensure that the most dangerous dinosaurs are taken care of first. Write a
PriorityQueueclass that sorts dinosaurs based on a customComparatorinterface, such as their danger level. - Generics can make our code more reusable. Create a class called
Cratewith a generic for the thing you’d like to store in there. This could be food or drinks for the restaurant, but also dinosaurs if we need to relocate them. - Create three instances of your
Crateclass with different classes in your program – for example,Dinosaur,Jeep, andDinosaurFood. - Hashing is essential for efficient data handling. Override...