# Example for Introduction to Generics in Java

What are some good example classes for introducing generics in Java?

I'm introducing this in the context of implementing ArrayList, but I don't want my first example to be ArrayList itself due to the inability to create arrays of a generic type. I would also like my example to be something that doesn't seem contrived/has a practical use.

• "Implementing" ArrayList or using the library class ArrayList from Collections? – Buffy Oct 5 '18 at 10:48
• You can pretty easily do a linked list. – ncmathsadist Oct 10 '18 at 13:17
• @ncmathsadist Definitely, but I wanted to introduce generics between array list and linked list, so that we could start off using linked lists with generics. I'm happy with the pair example mentioned below - it went over well in class. – cryptic_star Oct 10 '18 at 13:49

While uniform collections are the obvious example, you can also build or use a Pair class in which the types of the two components are given by generic arguments. If you don't want to build it, there is a built-in class with this property: $$Pair$$