ArrayList
Node
classPreliminary version. Changes are likely.
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,
and perhaps even several linked lists for different types of objects.
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 work.
Better would be to create a generic linked list
that could be used with whatever type of object you need.
This is what Java generics enables you to do.
(Review: ) What type of object does the following code construct?
ArrayList<String> names = new ArrayList<String>() ;