created: 07/30/2019; revised 08/10/2025

go to home page   go to next page highlighting

CHAPTER 133 — Generic Linked List

Chapter Topics:

The previous chapters built linked lists containing primitive type int. A practical application would likely need a linked list that held objects of some type relevant to the application. Perhaps even several linked lists of different types of objects would be needed.

Say you needed a linked list of String, a linked list of Integer, and a linked list of MyOwnType. You could write a linked list for each of these types. But that would entail a lot of duplicated effort. It would be better to create an all-purpose linked list that could be used with whatever type of object you need. This is what Java generics enable you to do.

(In actual practice you would use the LinkedList class of the Java Collections Framework. But lets ignore that for now.)


QUESTION 1:

(Review: ) What type of object does the following code construct?

ArrayList<String> names = new ArrayList<String>() ;

go to home page   go to next page