Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. Lists > Exercises

3.5. Exercises

  1. Write a constructor for ArrayList that accepts a standard Java array to initially populate List.

  2. Write an equals() method that will work for any List implementation.

  3. Write a toString() method that will work for any List implementation that prints the contents as a single line with values surrounded by square brackets and separated by commas. For example, "[A, B, C]" or "[]" for an empty List.

  4. Create an Iterator that will work for any List implementation. What are the performance implications?

  5. Update LinkedList to traverse backward if, when inserting and deleting, the desired index is more than halfway along the list.

  6. Rewrite indexOf() so that it will work for any list.

  7. Create a List implementation that is always empty and throws UnsupportedOperationException if an attempt is made to modify it.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial