21.4.2 Implementing a Generic List Class

The program of Figs. 21.321.5 uses an object of our generic List class to manipulate a list of miscellaneous objects. The program consists of four classes—ListNode (Fig. 21.3, lines 6–37), List (Fig. 21.3, lines 40–147), EmptyListException (Fig. 21.4) and ListTest (Fig. 21.5). Encapsulated in each List object is a linked list of ListNode objects.

 1   // Fig. 21.3: List.java 2   // ListNode and List class declarations. 3   package com.deitel.datastructures; 4  5   // class to represent one node in a list 6   class ListNode<T> 7   { 8      // package access members; List can access these directly 9      T data; // data for this node10      ListNode<T> nextNode; // reference ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.