14.11 Linked Lists Using Generic Types

Many classes in the Java Class Library, such as the ArrayList class, implement generics, meaning that the data type for the data of the class can be specified by the client. User-defined classes can also implement generic types. In this section, we will build a linked list class that implements generic types, so that the client can specify the class type of the data stored in our linked list. In a linked list, the data of the item is stored in the node; thus, the data in our Node class will be a generic object.

The basic syntax for the header of a class that implements generics is:

accessModifier class ClassName<IdentifierForGenericClass>

For the identifier for our generic class, we will use the uppercase ...

Get Java Illuminated, 5th 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.