ArrayList
Node
class
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.)
(Review: ) What type of object does the following code construct?
ArrayList<String> names = new ArrayList<String>() ;