Answers.Body: <p>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: <span class="math-container">$Pair&lt;K,V&gt;$</span></p>
  
  <p>But building one like it is simple enough if that is your goal. </p>
  
  <p>Once you have your desired class, Write a function/method that needs to return two things instead of one. Bundle them up in a Pair. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T11:07:33.473Z
Answers.Text: Perfect! Thank you! This is a very obvious one. I suppose that's what I get for making slides at night.
Answers.UserDisplayName: cryptic_star
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T10:54:30.843Z
Answers.LastActivityDate: 2018-10-05T10:54:30.843Z
Answers.UserDisplayName: Buffy
Body: <p>What are some good example classes for introducing generics in Java?</p>
  
  <p>I'm introducing this in the context of implementing <code>ArrayList</code>, but I don't want my first example to be <code>ArrayList</code> 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.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-05T10:48:03.327Z
Comments.Text: "Implementing" ArrayList or using the library class ArrayList from Collections?
Comments.UserDisplayName: Buffy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-10T13:17:35.270Z
Comments.Text: You can pretty easily do a linked list.
Comments.UserDisplayName: ncmathsadist
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-10T13:49:04.050Z
Comments.Text: @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.
Comments.UserDisplayName: cryptic_star
Tags: <java><data-structure><data-types><generics>
Title: Example for Introduction to Generics in Java
ThreadText: # Example for Introduction to Generics in Java
  
  (Asked by: username_0 on 2018-10-05)
  
  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.
  
  **Tags:** java, data-structure, data-types, generics
  
  > **Comments:**
  > **username_1**: "Implementing" ArrayList or using the library class ArrayList from Collections?  
  > **username_2**: You can pretty easily do a linked list.  
  > **username_0**: @username_2 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-10-05. Score: 3 | Accepted answer
  
  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<K,V>$
  
  But building one like it is simple enough if that is your goal.
  
  Once you have your desired class, Write a function/method that needs to return two things instead of one. Bundle them up in a Pair.
  
  > **Comments:**
  > **username_0**: Perfect! Thank you! This is a very obvious one. I suppose that's what I get for making slides at night.  
  
  ---
  
  