[ Pobierz całość w formacie PDF ]
.[ Add Comment ]Takethe Gerbil class in Exercise 2 and put it into a Map instead,associating the name of the Gerbil as a String (the key) for eachGerbil (the value) you put in the table.Get an Iterator for thekeySet( ) and use it to move through the Map, looking up theGerbil for each key and printing out the key and telling thegerbil to hop( ).[ Add Comment ]Createa List (try both ArrayList and LinkedList) and fillit using Collections2.countries.Sort the list and print it, then applyCollections.shuffle( ) to the list repeatedly, printing it each timeso that you can see how the shuffle( ) method randomizes the listdifferently each time.[ Add Comment ]Demonstratethat you can’t add anything but a Mouse to a MouseList.[ Add Comment ]ModifyMouseList.java so that it inherits from ArrayList instead of usingcomposition.Demonstrate the problem with this approach.[ Add Comment ]RepairCatsAndDogs.java by creating a Cats container (utilizingArrayList) that will only accept and retrieve Cat objects.[ Add Comment ]Createa container that encapsulates an array of String, and that only addsStrings and gets Strings, so that there are no casting issuesduring use.If the internal array isn’t big enough for the next add, yourcontainer should automatically resize it.In main( ), compare theperformance of your container with an ArrayList holding Strings.[ Add Comment ]RepeatExercise 9 for a container of int, and compare the performance to anArrayList holding Integer objects.In your performance comparison,include the process of incrementing each object in the container.[ Add Comment ]Usingthe utilities in com.bruceeckel.util, create an array of each primitivetype and of String, then fill each array using an appropriate generator,and print each array using the appropriate print( ) method.[ Add Comment ]Createa generator that produces character names from your favorite movies (you can useSnow White or Star Wars as a fallback), and loops around to thebeginning when it runs out of names.Use the utilities incom.bruceeckel.util to fill an array, an ArrayList, aLinkedList and both types of Set, then print each container.[ Add Comment ]Createa class containing two String objects, and make it Comparable sothat the comparison only cares about the first String.Fill an array andan ArrayList with objects of your class, using the geographygenerator.Demonstrate that sorting works properly.Now make aComparator that only cares about the second String and demonstratethat sorting works properly; also perform a binary search using yourComparator.[ Add Comment ]ModifyExercise 13 so that an alphabetic sort is used.[ Add Comment ]UseArrays2.RandStringGenerator to fill a TreeSet but using alphabeticordering.Print the TreeSet to verify the sort order.[ Add Comment ]Createboth an ArrayList and a LinkedList, and fill each using theCollections2.capitals generator.Print each list using an ordinaryIterator, then insert one list into the other using aListIterator, inserting at every other location.Now perform theinsertion starting at the end of the first list and moving backward.[ Add Comment ]Writea method that uses an Iterator to step through a Collection andprint the hashCode( ) of each object in the container.Fill all thedifferent types of Collections with objects and apply your method to eachcontainer.[ Add Comment ]Repairthe problem in InfiniteRecursion.java.[ Add Comment ]Createa class, then make an initialized array of objects of your class.Fill aList from your array.Create a subset of your List usingsubList( ), and then remove this subset from your List usingremoveAll( ).[ Add Comment ]ChangeExercise 6 in Chapter 7 to use an ArrayList to hold the Rodentsand an Iterator to move through the sequence of Rodents.Rememberthat an ArrayList holds only Objects so you must use a cast whenaccessing individual Rodents.[ Add Comment ]Followingthe Queue.java example, create a Deque class and test it.[ Add Comment ]Usea TreeMap in Statistics.java.Now add code that tests theperformance difference between HashMap and TreeMap in thatprogram.[ Add Comment ]Producea Map and a Set containing all the countries that begin with‘A.’[ Add Comment ]UsingCollections2.countries, fill a Set multiple times with the samedata and verify that the Set ends up with only one of each instance.Trythis with both kinds of Set.[ Add Comment ]Startingwith Statistics.java, create a program that runs the test repeatedly andlooks to see if any one number tends to appear more than the others in theresults.[ Add Comment ]RewriteStatistics
[ Pobierz całość w formacie PDF ]