# Collection Framework Cheat Sheet

<table>
  <tr>
    <th>Collection Classes</th>
    <th>Duplicates Accepted?</th>
    <th>Insertion Order maintained?</th>
    <th>Sorted Order?</th>
    <th>Is Thread Safe?</th>
  </tr>
  <tr><td>**List **</td></tr>
  <tr>
    <td>ArrayList</td>
    <td>**Yes**</td>
    <td>**Yes**</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>LinkeList</td>
    <td>**Yes**</td>
    <td>**Yes**</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>Vector</td>
    <td>**Yes**</td>
    <td>**Yes**</td>
    <td>No</td>
    <td>**Yes**</td>
  </tr>
  <tr><td>**Set**</td></tr>
  <tr>
    <td>HashSet</td>
    <td>No</td>
    <td>No</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>LinkedHashSet</td>
    <td>No</td>
    <td>**Yes**</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>TreeSet</td>
    <td>No</td>
    <td>**Yes**</td>
    <td>**Yes**</td>
    <td>No</td>
  </tr>
  <tr><td>**Map**</td></tr>
  <tr>
    <td>HashMap</td>
    <td>No</td>
    <td>No</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>LinkedHashMap</td>
    <td>No</td>
    <td>**Yes**</td>
    <td>No</td>
    <td>No</td>
  </tr>
  <tr>
    <td>Hashtable</td>
    <td>No</td>
    <td>No</td>
    <td>No</td>
    <td>**Yes**</td>
  </tr>
  <tr>
    <td>TreeMap</td>
    <td>No</td>
    <td>**Yes**</td>
    <td>**Yes**</td>
    <td>No</td>
  </tr>
</table>


- *All lists* allow duplicate elements and follow *insertion order*.
- All *list* elements are *not sorted*.
- All sets and maps do not allow duplicate elements.
- *Sets *and *maps *do *not sort *their elements, *except TreeSet and TreeMap* – in which elements are sorted by natural order or by a comparator.
- Elements within *sets and maps *are *not ordered*, except for:
<ul>
<li>*LinkedHashSet *and *LinkedHashMap *have elements *ordered by insertion order*.</li>
<li>*TreeSet *and *TreeMap *have elements ordered by *natural order or by a comparator*.</li>
</ul>
- There are only *two collections *that are *thread-safe*: *Vector *and *Hashtable*. The rest is not thread-safe.


Hope you have learned something new. If yes, share it with your friends and colleagues.

Let's meet at the other tech article next time. Until then stay connected with me on [LinkedIn](https://www.linkedin.com/in/saiphani1998/)

-- **P**asumarthi **S**ai **P**hani **K**rishna (aka PSPK)😊
