{"id":75337,"date":"2019-08-09T11:00:57","date_gmt":"2019-08-09T08:00:57","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=75337"},"modified":"2022-07-07T15:59:02","modified_gmt":"2022-07-07T12:59:02","slug":"java-collections-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/","title":{"rendered":"Java Collections Tutorial"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>A <a aria-label=\"collection  (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/collections\/intro\/index.html\" target=\"_blank\">collection<\/a> is a group of objects and treated as a single unit. It is used to store, retrieve, and manipulate aggregate data. Collections are part of the core java and all java developers must have familiarity with them. Java has provided a <a aria-label=\"collection framework (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Java_collections_framework\" target=\"_blank\">collection framework<\/a> which contains interfaces, classes, and algorithms since version 1.2 and enhanced it over time. The most important interfaces are Java Set, List, and Map. Here are some enhancements:<\/p>\n<ul class=\"wp-block-list\">\n<li>Major enhancement at <a aria-label=\"version 5 (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/collections\/changes5.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 5<\/a>, including generic type.<\/li>\n<li>Added more interfaces and classes at <a aria-label=\"version 6 (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/collections\/changes6.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 6<\/a>, including <code>Deque<\/code>, <code>BlockingDeque<\/code>, <code>NavigableSet<\/code>, <code>NavigableMap<\/code>, <code>ConcurrentNavigableMap<\/code>, etc.<\/li>\n<li>Added a new <code>TransferQueue<\/code> interface at <a aria-label=\"version 7 (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/guides\/collections\/changes7.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 7<\/a>.<\/li>\n<li><code>Collection<\/code> added the <code>foreach(Consumer&lt;? super T&gt;&gt; action)<\/code> method at <a aria-label=\"version 8 (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/technotes\/guides\/collections\/changes8.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 8<\/a>.<\/li>\n<li>Added factory methods for creating immutable lists at <a aria-label=\"version 9 (opens in a new tab)\" href=\"https:\/\/dzone.com\/articles\/java-9-collections-improvements\" target=\"_blank\" rel=\"noreferrer noopener\">version 9<\/a>, such as <code>static<\/code> <code>of()<\/code> method. <\/li>\n<li><code>List<\/code> added <code>static<\/code> <code>copyOf()<\/code> method at <a aria-label=\"version 10 (opens in a new tab)\" href=\"https:\/\/www.oracle.com\/technetwork\/java\/javase\/10-relnote-issues-4108729.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 10<\/a>. <\/li>\n<li><code>Collection<\/code> added a new default method&nbsp;<code>toArray(IntFunction&lt;T[]&gt; generator)<\/code> at <a aria-label=\"version 11 (opens in a new tab)\" href=\"https:\/\/www.oracle.com\/technetwork\/java\/javase\/11-relnote-issues-5012449.html\" target=\"_blank\" rel=\"noreferrer noopener\">version 11<\/a>.<\/li>\n<\/ul>\n<p>You can also check this tutorial in the following video:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/www.youtube.com\/watch?v=m6rXF9KrbLs\"><img decoding=\"async\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Java-Collections-Tutorial-1024x576.jpg\" alt=\"\" class=\"wp-image-113806\" width=\"512\" height=\"288\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Java-Collections-Tutorial-1024x576.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Java-Collections-Tutorial-300x169.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Java-Collections-Tutorial-768x432.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Java-Collections-Tutorial.jpg 1280w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><figcaption>Java Collections Tutorial &#8211; video<\/figcaption><\/figure>\n<\/div>\n<p>In this example, I will create several test classes to demonstrate how to use the most commonly used interfaces: <code>List<\/code>, <code>Set<\/code>, <code>Queue<\/code> and classes: <code>ArrayList<\/code>, <code>LinkedList<\/code>, <code>Vector<\/code>, <code>Stack<\/code>, <code>HashSet<\/code>, <code>TreeSet<\/code>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"662\" height=\"530\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/collections.jpg\" alt=\"Java Collections\" class=\"wp-image-75449\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/collections.jpg 662w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/collections-300x240.jpg 300w\" sizes=\"(max-width: 662px) 100vw, 662px\" \/><figcaption>Figure 1 Collections<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-2-technologies-used\">2. Technologies Used<\/h2>\n<p>The example code in this article was built and run using:<\/p>\n<ul class=\"wp-block-list\">\n<li>Java 11<\/li>\n<li>Maven 3.3.9<\/li>\n<li>Eclipse Oxygen<\/li>\n<li>Logback 1.2.3<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-3-maven-project\">3. Maven Project<\/h2>\n<h3 class=\"wp-block-heading\" id=\"h-3-1-pom-xml\">3.1 Pom.xml<\/h3>\n<p><code>Pom.xml<\/code>&nbsp;manages the project dependencies.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\"\n\txmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;jcg.zheng.demo&lt;\/groupId&gt;\n\t&lt;artifactId&gt;java-collections-demo&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;build&gt;\n\t\t&lt;sourceDirectory&gt;src&lt;\/sourceDirectory&gt;\n\t\t&lt;plugins&gt;\n\t\t\t&lt;plugin&gt;\n\t\t\t\t&lt;artifactId&gt;maven-compiler-plugin&lt;\/artifactId&gt;\n\t\t\t\t&lt;version&gt;3.8.0&lt;\/version&gt;\n\t\t\t\t&lt;configuration&gt;\n\t\t\t\t\t&lt;release&gt;11&lt;\/release&gt;\n\t\t\t\t&lt;\/configuration&gt;\n\t\t\t&lt;\/plugin&gt;\n\t\t&lt;\/plugins&gt;\n\t&lt;\/build&gt;\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;junit&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;junit&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;4.12&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;logback-access&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.2.3&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;logback-classic&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.2.3&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;logback-core&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;1.2.3&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n&lt;\/project&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-3-2-somedata\">3.2 SomeData<\/h3>\n<p>Java collection classes work with <a aria-label=\"Object  (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Object.html\" target=\"_blank\">Object<\/a>, not the primitive data type. In this step, I will create a <code>SomeData<\/code> class which implements the <code>Comparable<\/code> interface.<\/p>\n<p><span style=\"text-decoration: underline\"><em>SomeData.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo.data;\n\nimport java.io.Serializable;\n\npublic class SomeData implements Comparable , Serializable {\n\n\tprivate static final long serialVersionUID = -5243901184267064976L;\n\n\tprivate int id;\n\n\tprivate String name;\n\n\t@Override\n\tpublic boolean equals(Object obj) {\n\t\tif (this == obj)\n\t\t\treturn true;\n\t\tif (obj == null)\n\t\t\treturn false;\n\t\tif (getClass() != obj.getClass())\n\t\t\treturn false;\n\t\tSomeData other = (SomeData) obj;\n\t\tif (id != other.id)\n\t\t\treturn false;\n\t\tif (name == null) {\n\t\t\tif (other.name != null)\n\t\t\t\treturn false;\n\t\t} else if (!name.equals(other.name))\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tfinal int prime = 31;\n\t\tint result = 1;\n\t\tresult = prime * result + id;\n\t\tresult = prime * result + ((name == null) ? 0 : name.hashCode());\n\t\treturn result;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"SomeData [name=\" + name + \", id=\" + id + \"]\";\n\t}\n\n\t@Override\n\tpublic int compareTo(SomeData other) {\n\t\tint byName = this.name.compareTo(other.getName());\n\t\treturn byName;\n\t}\n\n}\n<\/pre>\n<h2 class=\"wp-block-heading\" id=\"h-4-abstract-test-classes\">4. Abstract Test Classes<\/h2>\n<p>In this step, I will create three abstract test classes:<\/p>\n<ul class=\"wp-block-list\">\n<li><code>CollectionBase_POJOTest<\/code> &#8211; It demonstrates how to <code>add<\/code>, <code>remove<\/code>, <code>clear<\/code>, <code>contains<\/code>, <code>getSize<\/code>, <code>foreach<\/code> for a <code>Collection<\/code> of <code>SomeData<\/code> objects. <\/li>\n<li><code>CollectionBase_StringTest<\/code> &#8211; It does the same as above class but for <code>String<\/code> objects.<\/li>\n<li><code>ListBase_StringTest<\/code> &#8211; It extends from <code>CollectionBase_StringTest<\/code> with additional test methods for the <code>List<\/code> interface with <code>String<\/code> objects.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-4-1-collectionbase-stringtest\">4.1 CollectionBase_StringTest<\/h3>\n<p>The <code>Collection<\/code> interface includes methods to add, remove, and retrieve elements from a collection. It checks the element&#8217;s existence with the <code>contains<\/code> method. In this example, I will create a test class which demonstrates how to use these methods for <code>String<\/code> objects.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CollectionBase_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Iterator;\n\nimport org.junit.After;\nimport org.junit.FixMethodOrder;\nimport org.junit.Test;\nimport org.junit.runners.MethodSorters;\nimport org.slf4j.Logger;\n\n@FixMethodOrder(MethodSorters.NAME_ASCENDING)\npublic abstract class CollectionBase_StringTest {\n\n\tprotected Collection&lt;String&gt; colItems;\n\n\tprotected Logger logger;\n\n\t@Test\n\tpublic void Collection_add() {\n\t\tcolItems.add(\"new Item\");\n\t\tassertEquals(5, colItems.size());\n\n\t\tlogger.info(\"The arraycolItems contains the following elements: \" + colItems);\n\t}\n\n\t@After\n\tpublic void Collection_clear() {\n\t\tcolItems.clear();\n\t\tassertTrue(colItems.isEmpty());\n\t}\n\n\t@Test\n\tpublic void Collection_contains() {\n\t\tassertTrue(colItems.contains(\"Item1\"));\n\t\tassertFalse(colItems.contains(\"Item5\"));\n\t}\n\n\t@Test\n\tpublic void Collection_getSize() {\n\t\tassertEquals(4, colItems.size());\n\t}\n\n\t@Test\n\tpublic void Collection_isEmpty() {\n\t\tassertFalse(colItems.isEmpty());\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_for() {\n\t\tlogger.info(\"Retrieving items using for loop\");\n\t\tfor (String str : colItems) {\n\t\t\tlogger.info(\"Item is: \" + str);\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_foreach_java8() {\n\t\tlogger.info(\"Retrieving items using Java 8 Stream\");\n\t\tcolItems.forEach((item) -&gt; {\n\t\t\tlogger.info(item);\n\t\t});\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_iterator_next() {\n\t\tlogger.info(\"Retrieving items using iterator\");\n\t\tfor (Iterator&lt;String&gt; it = colItems.iterator(); it.hasNext();) {\n\t\t\tlogger.info(\"Item is: \" + it.next());\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_iterator_while() {\n\t\tIterator&lt;String&gt; it = colItems.iterator();\n\t\tlogger.info(\"Retrieving items using iterator\");\n\t\twhile (it.hasNext()) {\n\t\t\tlogger.info(\"Item is: \" + it.next());\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_remove() {\n\t\tboolean removed = colItems.remove(\"Item1\");\n\t\tassertTrue(removed);\n\t\tassertEquals(3, colItems.size());\n\n\t\tcolItems.remove(\"Item3\");\n\t\tassertEquals(2, colItems.size());\n\t}\n\n\t@Test\n\tpublic void Collection_remove_via_iterator_remove() {\n\t\tlogger.info(\"Removing items using iterator\");\n\t\tfor (Iterator&lt;String&gt; it = colItems.iterator(); it.hasNext();) {\n\t\t\tString item = it.next();\n\t\t\tlogger.info(\"Item is: \" + item);\n\t\t\tit.remove();\n\t\t\tassertFalse(colItems.contains(item));\n\t\t}\n\n\t\tassertTrue(colItems.isEmpty());\n\t}\n\n\t@Test\n\tpublic void Collection_toArray_default_java11() {\n\t\tString[] simpleArray = colItems.toArray(new String[colItems.size()]);\n\t\tlogger.info(\"The array created after the conversion of our arraycolItems is: \" + Arrays.toString(simpleArray));\n\n\t\tString[] testArr = colItems.toArray(size -&gt; new String[size]);\n\t\tlogger.info(\"default toArray(intfunction):\" + Arrays.toString(testArr));\n\t}\n}<\/pre>\n<p><strong>Note<\/strong>: the <code>colItems<\/code> variable is a type of <code>Collection&lt;String&gt;<\/code><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-2-collectionbase-pojotest\">4.2 CollectionBase_POJOTest<\/h3>\n<p>In this step, I will create a <code>CollectionBase_POJOTest<\/code> class which has the same methods as the <code>CollectionBase_StringTest<\/code> class but with the <code>SomeData<\/code> type.<\/p>\n<p><span style=\"text-decoration: underline\"><em>CollectionBase_POJOTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertFalse;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Iterator;\n\nimport org.junit.After;\nimport org.junit.FixMethodOrder;\nimport org.junit.Test;\nimport org.junit.runners.MethodSorters;\nimport org.slf4j.Logger;\n\nimport jcg.zheng.demo.data.SomeData;\n\n@FixMethodOrder(MethodSorters.NAME_ASCENDING)\npublic abstract class CollectionBase_POJOTest {\n\n\tCollection&lt;SomeData&gt; list;\n\n\tprotected Logger logger;\n\n\tprotected SomeData buildSomeData(int id, String name) {\n\t\tSomeData sd = new SomeData();\n\t\tsd.setId(id);\n\t\tsd.setName(name);\n\t\treturn sd;\n\t}\n\n\t@Test\n\tpublic void Collection_add() {\n\t\tlist.add(buildSomeData(1, \"test\"));\n\t\tassertEquals(5, list.size());\n\n\t\tlogger.info(\"The arraylist contains the following elements: \" + list);\n\t}\n\n\t@After\n\tpublic void Collection_clear() {\n\t\tlist.clear();\n\t\tassertTrue(list.isEmpty());\n\t}\n\n\t@Test\n\tpublic void Collection_contains() {\n\t\tassertTrue(list.contains(buildSomeData(1, \"Item1\")));\n\t\tassertFalse(list.contains(buildSomeData(5, \"Item5\")));\n\t}\n\n\t@Test\n\tpublic void Collection_getSize() {\n\t\tassertEquals(4, list.size());\n\t}\n\n\t@Test\n\tpublic void Collection_isEmpty() {\n\t\tassertFalse(list.isEmpty());\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_for() {\n\t\tlogger.info(\"Retrieving items using for loop\");\n\t\tfor (SomeData str : list) {\n\t\t\tlogger.info(\"Item is: \" + str);\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_foreach_lambda() {\n\t\tlogger.info(\"Retrieving items using Java 8 Stream\");\n\t\tlist.forEach((item) -&gt; {\n\t\t\tlogger.info(item.toString());\n\t\t});\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_iterator_for() {\n\t\tlogger.info(\"Retrieving items using iterator\");\n\t\tfor (Iterator&lt;SomeData&gt; it = list.iterator(); it.hasNext();) {\n\t\t\tlogger.info(\"Item is: \" + it.next().toString());\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_loop_via_iterator_while() {\n\t\tIterator&lt;SomeData&gt; it = list.iterator();\n\t\tlogger.info(\"Retrieving items using iterator\");\n\t\twhile (it.hasNext()) {\n\t\t\tlogger.info(\"Item is: \" + it.next().toString());\n\t\t}\n\t}\n\n\t@Test\n\tpublic void Collection_remove() {\n\t\tlist.remove(buildSomeData(3, \"Item3\"));\n\t\tassertEquals(3, list.size());\n\t}\n\n\t@Test\n\tpublic void Collection_toArray() {\n\t\tSomeData[] simpleArray = list.toArray(new SomeData[list.size()]);\n\t\tlogger.info(\"The array created after the conversion of our arraylist is: \" + Arrays.toString(simpleArray));\n\t}\n}<\/pre>\n<p><strong>Note<\/strong>: the <code>list<\/code> variable is a type of <code>Collection&lt;SomeData&gt;<\/code><\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-3-listbase-stringtest\">4.3 ListBase_StringTest<\/h3>\n<p>The <a aria-label=\"List  (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/List.html\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a> interface extends from the <a aria-label=\"Collection (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Collection.html\" target=\"_blank\" rel=\"noreferrer noopener\">Collection<\/a> interface with additional methods. In this step, I will demonstrate how to add, remove, and retrieve at a given index position for a <code>List<\/code> of <code>String<\/code>. I will also demonstrate two Collections algorithms with the <code>sort<\/code> and <code>binarySearch<\/code> methods.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ListBase_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Collections;\nimport java.util.List;\n\nimport org.junit.Test;\n\npublic abstract class ListBase_StringTest extends CollectionBase_StringTest {\n\n\tprotected List&lt;String&gt; listItems;\n\n\t@Test\n\tpublic void Collections_sort_binarySearch() {\n\t\tlistItems.add(\"Tom\");\n\t\tlistItems.add(\"Mary\");\n\t\tlistItems.add(\"Shan\");\n\t\tlistItems.add(\"Zheng\");\n\n\t\tCollections.sort(listItems);\n\t\tassertEquals(\"Mary\", listItems.get(0));\n\t\tassertEquals(\"Shan\", listItems.get(1));\n\t\tassertEquals(\"Tom\", listItems.get(2));\n\t\tassertEquals(\"Zheng\", listItems.get(3));\n\t\tlogger.info(\"Sorted List\");\n\t\tfor (int i = 0; i &lt; listItems.size(); i++) {\n\t\t\tlogger.info(\"Index: \" + i + \" - Item: \" + listItems.get(i));\n\t\t}\n\n\t\tint foundTom = Collections.binarySearch(listItems, \"Tom\");\n\t\tassertEquals(2, foundTom);\n\t}\n\n\t@Test\n\tpublic void List_can_add_get_remove_via_index() {\n\n\t\tlistItems.add(0, \"Mary\");\n\t\tassertEquals(1, listItems.size());\n\n\t\tint pos = listItems.indexOf(\"Mary\");\n\t\tassertEquals(0, pos);\n\n\t\tString item0 = listItems.get(0);\n\t\tassertEquals(\"Mary\", item0);\n\n\t\tlistItems.set(0, \"Zheng\");\n\t\tassertEquals(\"Zheng\", listItems.get(0));\n\n\t\tlistItems.remove(0);\n\t\tassertTrue(listItems.isEmpty());\n\n\t}\n\n\t@Test\n\tpublic void List_copyOf_java10() {\n\t\tlistItems.add(\"JCG\");\n\t\tlistItems.add(\"Demo\");\n\n\t\tList&lt;String&gt; copiedValues = List.copyOf(listItems);\n\t\tassertEquals(2, copiedValues.size());\n\t}\n\n\t@Test\n\tpublic void List_loop_via_for_get_index() {\n\t\tlistItems.add(\"Tom\");\n\t\tlistItems.add(\"Mary\");\n\t\tlistItems.add(\"Shan\");\n\t\tlistItems.add(\"Zheng\");\n\n\t\tlogger.info(\"Retrieving items with loop using index and size list\");\n\t\tfor (int i = 0; i &lt; listItems.size(); i++) {\n\t\t\tlogger.info(\"Index: \" + i + \" - Item: \" + listItems.get(i));\n\t\t}\n\t}\n\n\t@Test\n\tpublic void List_of_java9() {\n\t\tList&lt;String&gt; emptyList = List.of();\n\t\tassertTrue(emptyList.isEmpty());\n\n\t\tList&lt;String&gt; itemList = List.of(\"Mary\", \"Zheng\", \"Developer\");\n\t\tassertEquals(3, itemList.size());\n\t}\n\n}\n<\/pre>\n<p><strong>Note<\/strong>: the <code>listItems<\/code> variable is a type of <code>List&lt;String&gt;<\/code><\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-test-classes\">5. Test Classes<\/h2>\n<p>In this step, I will create test classes for the commonly used <code>Collection<\/code> classes. Each test class is extends from one of the three abstract test classes with its unique operations. The test method is named as <code>{$InterfaceName}_{$MethodName}<\/code>. <\/p>\n<h3 class=\"wp-block-heading\" id=\"h-5-1-arraylist-stringtest\">5.1 ArrayList_StringTest<\/h3>\n<p><a aria-label=\"ArrayList  (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/ArrayList.html\" target=\"_blank\" rel=\"noreferrer noopener\">ArrayList<\/a> implements <a aria-label=\"List (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/List.html\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a>, <a aria-label=\"Serializable (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/io\/Serializable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Serializable<\/a>, <a aria-label=\"Cloneable (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Cloneable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Cloneable<\/a>, <a aria-label=\"Iterable (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Iterable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Iterable<\/a>, <a aria-label=\"Collection (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Collection.html\" target=\"_blank\" rel=\"noreferrer noopener\">Collection<\/a>, and <a aria-label=\"RandomAccess  (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/RandomAccess.html\" target=\"_blank\" rel=\"noreferrer noopener\">RandomAccess<\/a> interfaces. It is used to store dynamically sized collection of elements.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>In this step, I will create an <code>ArrayList_StringTest<\/code> class which extends from <code>ListBase_StringTest<\/code>. <\/p>\n<p>In the <code>setup_list_with_4_items<\/code> method, it will create an <code>ArrayList<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>ArrayList_clone<\/code> method, it will clone an array list.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ArrayList_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.ArrayList;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\npublic class ArrayList_StringTest extends ListBase_StringTest {\n\n @SuppressWarnings(\"unchecked\")\n @Test\n public void Object_clone() {\n ArrayList&lt;String&gt; arrList = (ArrayList&lt;String&gt;) listItems;\n arrList.add(\"Mary\");\n arrList.add(\"JCG\");\n\n ArrayList&lt;String&gt; cloneArr = (ArrayList&lt;String&gt;) arrList.clone();\n assertEquals(2, cloneArr.size());\n }\n\n @Before\n public void setup_list_with_4_items() {\n logger = LoggerFactory.getLogger(this.getClass());\n\n colItems = new ArrayList&lt;String&gt;();\n assertTrue(colItems.isEmpty());\n\n colItems.add(\"Item1\");\n assertEquals(1, colItems.size());\n colItems.add(\"Item2\");\n assertEquals(2, colItems.size());\n colItems.add(\"Item3\");\n assertEquals(3, colItems.size());\n colItems.add(\"Item4\");\n assertEquals(4, colItems.size());\n\n listItems = new ArrayList&lt;String&gt;();\n listItems.addAll(colItems);\n assertEquals(4, listItems.size());\n listItems.clear();\n\n }\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=ArrayList_StringTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.ArrayList_StringTest\n05:19:33.334 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Retrieving items with loop using index and size list\n05:19:33.377 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 0 - Item: Tom\n05:19:33.377 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 1 - Item: Mary\n05:19:33.377 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 2 - Item: Shan\n05:19:33.377 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 3 - Item: Zheng\n05:19:33.381 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Sorted List\n05:19:33.383 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 0 - Item: Mary\n05:19:33.384 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 1 - Item: Shan\n05:19:33.384 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 2 - Item: Tom\n05:19:33.390 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Index: 3 - Item: Zheng\n05:19:33.417 [main] INFO jcg.zheng.demo.ArrayList_StringTest - The arraycolItems contains the following elements: [Item1, Item2, Item3, Item4, new Item]\n05:19:33.425 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Retrieving items using for loop\n05:19:33.426 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item1\n05:19:33.427 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item2\n05:19:33.427 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item3\n05:19:33.427 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item4\n05:19:33.428 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Retrieving items using Java 8 Stream\n05:19:33.431 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item1\n05:19:33.431 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item2\n05:19:33.431 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item3\n05:19:33.431 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item4\n05:19:33.432 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Retrieving items using iterator\n05:19:33.432 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item1\n05:19:33.433 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item2\n05:19:33.433 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item3\n05:19:33.433 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item4\n05:19:33.434 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Retrieving items using iterator\n05:19:33.435 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item1\n05:19:33.436 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item2\n05:19:33.437 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item3\n05:19:33.437 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item4\n05:19:33.445 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Removing items using iterator\n05:19:33.446 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item1\n05:19:33.446 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item2\n05:19:33.447 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item3\n05:19:33.448 [main] INFO jcg.zheng.demo.ArrayList_StringTest - Item is: Item4\n05:19:33.455 [main] INFO jcg.zheng.demo.ArrayList_StringTest - The array created after the conversion of our arraycolItems is: [Item1, Item2, Item3, Item4]\n05:19:33.458 [main] INFO jcg.zheng.demo.ArrayList_StringTest - default toArray(intfunction):[Item1, Item2, Item3, Item4]\nTests run: 17, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.526 sec\n\nResults :\n\nTests run: 17, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  11.850 s\n[INFO] Finished at: 2019-08-04T05:19:33-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-2-linkedlist-stringtest\">5.2 LinkedList_StringTest<\/h3>\n<p><a aria-label=\"LinkedList (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/LinkedList.html\" target=\"_blank\" rel=\"noreferrer noopener\">LinkedList<\/a> implements <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/io\/Serializable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Serializable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Cloneable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Cloneable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Iterable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Iterable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Collection.html\" target=\"_blank\" rel=\"noreferrer noopener\">Collection<\/a>, <a aria-label=\"List  (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/List.html\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a> and <a aria-label=\"Queue (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Queue.html\" target=\"_blank\" rel=\"noreferrer noopener\">Queue<\/a> interfaces. It models the <a aria-label=\"linked-list data structure (opens in a new tab)\" href=\"https:\/\/en.wikipedia.org\/wiki\/Linked_list\" target=\"_blank\" rel=\"noreferrer noopener\">linked-list data structure<\/a>.<\/p>\n<p>In this step, I will create a <code>LinkedList_StringTest<\/code> class which extends from <code>ListBase_StringTest<\/code>. <\/p>\n<p>In the <code>setup_colItem_with_4_items<\/code> method, it will create a <code>LinkedList<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>DeQue_peekFirst_peekLast<\/code> method, it will find the first element and last element from the <code>DeQue<\/code> interface&#8217;s methods.<\/p>\n<p>In the <code>DeQue_peek<\/code> method, it will find the head element from <code>Deque<\/code>&#8216;s method.<\/p>\n<p><span style=\"text-decoration: underline\"><em>LinkedList_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.LinkedList;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\npublic class LinkedList_StringTest extends ListBase_StringTest {\n\n @Test\n public void DeQue_peekFirst_peekLast() {\n LinkedList&lt;String&gt; linkedLst = (LinkedList&lt;String&gt;) listItems;\n linkedLst.add(\"Mary\");\n linkedLst.add(\"Zheng\");\n\n assertEquals(\"Mary\", linkedLst.peekFirst());\n assertEquals(\"Zheng\", linkedLst.peekLast());\n\n assertEquals(\"Mary\", linkedLst.peek());\n }\n\n @Test\n public void DeQue_peek() {\n LinkedList&lt;String&gt; linkedLst = (LinkedList&lt;String&gt;) listItems;\n linkedLst.add(\"Mary\");\n linkedLst.add(\"Zheng\");\n\n assertEquals(\"Mary\", linkedLst.peek());\n }\n\n @Before\n public void setup_colItems_with_4_items() {\n logger = LoggerFactory.getLogger(this.getClass());\n\n colItems = new LinkedList&lt;String&gt;();\n assertTrue(colItems.isEmpty());\n\n colItems.add(\"Item1\");\n assertEquals(1, colItems.size());\n colItems.add(\"Item2\");\n assertEquals(2, colItems.size());\n colItems.add(\"Item3\");\n assertEquals(3, colItems.size());\n colItems.add(\"Item4\");\n assertEquals(4, colItems.size());\n\n listItems = new LinkedList&lt;String&gt;();\n listItems.addAll(colItems);\n assertEquals(4, listItems.size());\n listItems.clear();\n }\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=LinkedList_StringTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.LinkedList_StringTest\n05:22:22.802 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Retrieving items with loop using index and size list\n05:22:22.865 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 0 - Item: Tom\n05:22:22.866 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 1 - Item: Mary\n05:22:22.867 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 2 - Item: Shan\n05:22:22.869 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 3 - Item: Zheng\n05:22:22.873 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Sorted List\n05:22:22.875 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 0 - Item: Mary\n05:22:22.876 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 1 - Item: Shan\n05:22:22.877 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 2 - Item: Tom\n05:22:22.878 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Index: 3 - Item: Zheng\n05:22:22.908 [main] INFO jcg.zheng.demo.LinkedList_StringTest - The arraycolItems contains the following elements: [Item1, Item2, Item3, Item4, new Item]\n05:22:22.914 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Retrieving items using for loop\n05:22:22.915 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item1\n05:22:22.917 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item2\n05:22:22.918 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item3\n05:22:22.918 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item4\n05:22:22.920 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Retrieving items using Java 8 Stream\n05:22:22.921 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item1\n05:22:22.922 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item2\n05:22:22.922 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item3\n05:22:22.922 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item4\n05:22:22.922 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Retrieving items using iterator\n05:22:22.923 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item1\n05:22:22.923 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item2\n05:22:22.924 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item3\n05:22:22.925 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item4\n05:22:22.925 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Retrieving items using iterator\n05:22:22.926 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item1\n05:22:22.926 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item2\n05:22:22.926 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item3\n05:22:22.926 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item4\n05:22:22.930 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Removing items using iterator\n05:22:22.930 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item1\n05:22:22.931 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item2\n05:22:22.931 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item3\n05:22:22.932 [main] INFO jcg.zheng.demo.LinkedList_StringTest - Item is: Item4\n05:22:22.934 [main] INFO jcg.zheng.demo.LinkedList_StringTest - The array created after the conversion of our arraycolItems is: [Item1, Item2, Item3, Item4]\n05:22:22.936 [main] INFO jcg.zheng.demo.LinkedList_StringTest - default toArray(intfunction):[Item1, Item2, Item3, Item4]\nTests run: 18, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.726 sec\n\nResults :\n\nTests run: 18, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  13.643 s<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-3-vector-stringtestbase\">5.3 Vector_StringTestBase<\/h3>\n<p><a aria-label=\"Vector (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Vector.html\" target=\"_blank\" rel=\"noreferrer noopener\">Vector<\/a> implements <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/io\/Serializable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Serializable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Cloneable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Cloneable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/lang\/Iterable.html\" target=\"_blank\" rel=\"noreferrer noopener\">Iterable<\/a>, <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Collection.html\" target=\"_blank\" rel=\"noreferrer noopener\">Collection<\/a>, <a aria-label=\"List (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/List.html\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a>, and <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/RandomAccess.html\" target=\"_blank\" rel=\"noreferrer noopener\">RandomAccess<\/a> interfaces. It implements a grow-able array of objects.<\/p>\n<p>In this step, I will create a <code>Vector_StringTest<\/code> class which extends from <code>ListBase_StringTest<\/code>. <\/p>\n<p>In the <code>setup_colItems_with_4_items<\/code> method, it will create a <code>Vector<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>Vector_firstElement_lastElement<\/code> method, it will find the first and last elements.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Vector_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Vector;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\npublic class Vector_StringTest extends ListBase_StringTest {\n\n\t@Before\n\tpublic void setup_colItems_with_4_items() {\n\t\tlogger = LoggerFactory.getLogger(this.getClass());\n\n\t\tcolItems = new Vector&lt;String&gt;();\n\t\tassertTrue(colItems.isEmpty());\n\n\t\tcolItems.add(\"Item1\");\n\t\tassertEquals(1, colItems.size());\n\t\tcolItems.add(\"Item2\");\n\t\tassertEquals(2, colItems.size());\n\t\tcolItems.add(\"Item3\");\n\t\tassertEquals(3, colItems.size());\n\t\tcolItems.add(\"Item4\");\n\t\tassertEquals(4, colItems.size());\n\n\t\tlistItems = new Vector&lt;String&gt;();\n\t\tlistItems.addAll(colItems);\n\t\tassertEquals(4, listItems.size());\n\t\tlistItems.clear();\n\t}\n\n\t@Test\n\tpublic void Vector_firstElement_lastElement() {\n\t\tVector&lt;String&gt; vectorObj = (Vector&lt;String&gt;) listItems;\n\n\t\tvectorObj.add(\"Mary\");\n\t\tvectorObj.add(\"Zheng\");\n\t\tassertEquals(\"Mary\", vectorObj.firstElement());\n\t\tassertEquals(\"Zheng\", vectorObj.lastElement());\n\t}\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=Vector_StringTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.Vector_StringTest\n05:25:12.397 [main] INFO jcg.zheng.demo.Vector_StringTest - Retrieving items with loop using index and size list\n05:25:12.443 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 0 - Item: Tom\n05:25:12.443 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 1 - Item: Mary\n05:25:12.443 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 2 - Item: Shan\n05:25:12.443 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 3 - Item: Zheng\n05:25:12.447 [main] INFO jcg.zheng.demo.Vector_StringTest - Sorted List\n05:25:12.448 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 0 - Item: Mary\n05:25:12.448 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 1 - Item: Shan\n05:25:12.449 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 2 - Item: Tom\n05:25:12.449 [main] INFO jcg.zheng.demo.Vector_StringTest - Index: 3 - Item: Zheng\n05:25:12.488 [main] INFO jcg.zheng.demo.Vector_StringTest - The arraycolItems contains the following elements: [Item1, Item2, Item3, Item4, new Item]\n05:25:12.493 [main] INFO jcg.zheng.demo.Vector_StringTest - Retrieving items using for loop\n05:25:12.498 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item1\n05:25:12.498 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item2\n05:25:12.498 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item3\n05:25:12.498 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item4\n05:25:12.500 [main] INFO jcg.zheng.demo.Vector_StringTest - Retrieving items using Java 8 Stream\n05:25:12.501 [main] INFO jcg.zheng.demo.Vector_StringTest - Item1\n05:25:12.502 [main] INFO jcg.zheng.demo.Vector_StringTest - Item2\n05:25:12.502 [main] INFO jcg.zheng.demo.Vector_StringTest - Item3\n05:25:12.502 [main] INFO jcg.zheng.demo.Vector_StringTest - Item4\n05:25:12.503 [main] INFO jcg.zheng.demo.Vector_StringTest - Retrieving items using iterator\n05:25:12.504 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item1\n05:25:12.504 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item2\n05:25:12.504 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item3\n05:25:12.504 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item4\n05:25:12.505 [main] INFO jcg.zheng.demo.Vector_StringTest - Retrieving items using iterator\n05:25:12.507 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item1\n05:25:12.508 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item2\n05:25:12.508 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item3\n05:25:12.508 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item4\n05:25:12.516 [main] INFO jcg.zheng.demo.Vector_StringTest - Removing items using iterator\n05:25:12.517 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item1\n05:25:12.517 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item2\n05:25:12.518 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item3\n05:25:12.518 [main] INFO jcg.zheng.demo.Vector_StringTest - Item is: Item4\n05:25:12.522 [main] INFO jcg.zheng.demo.Vector_StringTest - The array created after the conversion of our arraycolItems is: [Item1, Item2, Item3, Item4]\n05:25:12.524 [main] INFO jcg.zheng.demo.Vector_StringTest - default toArray(intfunction):[Item1, Item2, Item3, Item4]\nTests run: 17, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.518 sec\n\nResults :\n\nTests run: 17, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  01:09 min\n[INFO] Finished at: 2019-08-04T05:25:12-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-4-stack-stringtest\">5.4 Stack_StringTest<\/h3>\n<p><a aria-label=\"Stack (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/Stack.html\" target=\"_blank\" rel=\"noreferrer noopener\">Stack<\/a> extends from Vector and implements <a aria-label=\"List  (opens in a new tab)\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/List.html\" target=\"_blank\" rel=\"noreferrer noopener\">List<\/a> interface. It models the <a aria-label=\"Stack data structure (opens in a new tab)\" href=\"https:\/\/en.wikipedia.org\/wiki\/Stack_(abstract_data_type)\" target=\"_blank\" rel=\"noreferrer noopener\">Stack data structure<\/a>.<\/p>\n<p>In this step, I will create a <code>Stack_StringTest<\/code> class which extends from <code>ListBase_StringTest<\/code>. <\/p>\n<p>In the <code>setup_colItems_with_4_items<\/code> method, it will create a <code>Stack<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>Stack_push_pop method<\/code>, it will push an element and pop an element based on first-in-last-out order.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Stack_StringTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Stack;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\npublic class Stack_StringTest extends ListBase_StringTest {\n\n @Before\n public void setup_colItems_with_4_items() {\n logger = LoggerFactory.getLogger(this.getClass());\n\n colItems = new Stack&lt;String&gt;();\n assertTrue(colItems.isEmpty());\n\n colItems.add(\"Item1\");\n assertEquals(1, colItems.size());\n colItems.add(\"Item2\");\n assertEquals(2, colItems.size());\n colItems.add(\"Item3\");\n assertEquals(3, colItems.size());\n colItems.add(\"Item4\");\n assertEquals(4, colItems.size());\n\n listItems = new Stack&lt;String&gt;();\n listItems.addAll(colItems);\n assertEquals(4, listItems.size());\n listItems.clear();\n }\n\n @Test\n public void Stack_push_pop() {\n ((Stack&lt;String&gt;) listItems).push(\"Mary\");\n String item = ((Stack&lt;String&gt;) listItems).pop();\n assertEquals(\"Mary\", item);\n }\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=Stack_StringTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.Stack_StringTest\n05:26:53.868 [main] INFO jcg.zheng.demo.Stack_StringTest - Retrieving items with loop using index and size list\n05:26:53.933 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 0 - Item: Tom\n05:26:53.934 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 1 - Item: Mary\n05:26:53.935 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 2 - Item: Shan\n05:26:53.936 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 3 - Item: Zheng\n05:26:53.939 [main] INFO jcg.zheng.demo.Stack_StringTest - Sorted List\n05:26:53.940 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 0 - Item: Mary\n05:26:53.942 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 1 - Item: Shan\n05:26:53.943 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 2 - Item: Tom\n05:26:53.943 [main] INFO jcg.zheng.demo.Stack_StringTest - Index: 3 - Item: Zheng\n05:26:53.973 [main] INFO jcg.zheng.demo.Stack_StringTest - The arraycolItems contains the following elements: [Item1, Item2, Item3, Item4, new Item]\n05:26:53.975 [main] INFO jcg.zheng.demo.Stack_StringTest - Retrieving items using for loop\n05:26:53.977 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item1\n05:26:53.978 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item2\n05:26:53.978 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item3\n05:26:53.978 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item4\n05:26:53.981 [main] INFO jcg.zheng.demo.Stack_StringTest - Retrieving items using Java 8 Stream\n05:26:53.984 [main] INFO jcg.zheng.demo.Stack_StringTest - Item1\n05:26:53.984 [main] INFO jcg.zheng.demo.Stack_StringTest - Item2\n05:26:53.984 [main] INFO jcg.zheng.demo.Stack_StringTest - Item3\n05:26:53.984 [main] INFO jcg.zheng.demo.Stack_StringTest - Item4\n05:26:53.985 [main] INFO jcg.zheng.demo.Stack_StringTest - Retrieving items using iterator\n05:26:53.986 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item1\n05:26:53.986 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item2\n05:26:53.986 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item3\n05:26:53.986 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item4\n05:26:53.987 [main] INFO jcg.zheng.demo.Stack_StringTest - Retrieving items using iterator\n05:26:53.988 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item1\n05:26:53.988 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item2\n05:26:53.988 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item3\n05:26:53.988 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item4\n05:26:53.994 [main] INFO jcg.zheng.demo.Stack_StringTest - Removing items using iterator\n05:26:53.995 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item1\n05:26:53.996 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item2\n05:26:53.996 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item3\n05:26:53.996 [main] INFO jcg.zheng.demo.Stack_StringTest - Item is: Item4\n05:26:53.997 [main] INFO jcg.zheng.demo.Stack_StringTest - The array created after the conversion of our arraycolItems is: [Item1, Item2, Item3, Item4]\n05:26:53.999 [main] INFO jcg.zheng.demo.Stack_StringTest - default toArray(intfunction):[Item1, Item2, Item3, Item4]\nTests run: 18, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.616 sec\n\nResults :\n\nTests run: 18, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  10.761 s\n[INFO] Finished at: 2019-08-04T05:26:54-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-5-arraylist-pojotest\">5.5 ArrayList_POJOTest<\/h3>\n<p>In this step, I will create an <code>ArrayList_POJOTest<\/code> class which extends from <code>CollectionBase_POJOTest<\/code>. <\/p>\n<p>In the <code>setup_list_with_4_items<\/code> method, it will create an <code>ArrayList<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ArrayList_POJOTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.ArrayList;\n\nimport org.junit.Before;\nimport org.slf4j.LoggerFactory;\n\nimport jcg.zheng.demo.data.SomeData;\n\npublic class ArrayList_POJOTest extends CollectionBase_POJOTest {\n\n\t@Before\n\tpublic void setup_list_with_4_items() {\n\t\tlogger = LoggerFactory.getLogger(this.getClass());\n\n\t\tlist = new ArrayList&lt;SomeData&gt;();\n\t\tassertTrue(list.isEmpty());\n\n\t\tlist.add(buildSomeData(1, \"Item1\"));\n\t\tassertEquals(1, list.size());\n\t\tlist.add(buildSomeData(2, \"Item2\"));\n\t\tassertEquals(2, list.size());\n\t\tlist.add(buildSomeData(3, \"Item3\"));\n\t\tassertEquals(3, list.size());\n\t\tlist.add(buildSomeData(4, \"Item4\"));\n\t\tassertEquals(4, list.size());\n\t}\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=ArrayList_POJOTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.ArrayList_POJOTest\n05:28:57.110 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - The arraylist contains the following elements: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4], SomeData [name=test, id=1]]\n05:28:57.127 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Retrieving items using for loop\n05:28:57.129 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:28:57.130 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:28:57.130 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:28:57.131 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:28:57.133 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Retrieving items using Java 8 Stream\n05:28:57.138 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - SomeData [name=Item1, id=1]\n05:28:57.139 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - SomeData [name=Item2, id=2]\n05:28:57.140 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - SomeData [name=Item3, id=3]\n05:28:57.140 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - SomeData [name=Item4, id=4]\n05:28:57.143 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Retrieving items using iterator\n05:28:57.145 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:28:57.145 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:28:57.145 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:28:57.145 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:28:57.147 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Retrieving items using iterator\n05:28:57.148 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:28:57.148 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:28:57.149 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:28:57.149 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:28:57.157 [main] INFO jcg.zheng.demo.ArrayList_POJOTest - The array created after the conversion of our arraylist is: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4]]\nTests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.473 sec\n\nResults :\n\nTests run: 10, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  10.397 s\n[INFO] Finished at: 2019-08-04T05:28:57-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-6-hashset-pojotest\">5.6 HashSet_POJOTest<\/h3>\n<p><a aria-label=\"HashSet (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/HashSet.html\" target=\"_blank\">HashSet<\/a> implements the Java Set interface. Java Set interface is implemented by HashSet, Treeset and other classes. It is used to store a collection of unique elements.<\/p>\n<p>In this step, I will create a <code>HashSet_POJOTest<\/code> class which extends from <code>CollectionBase_POJOTest<\/code>.<\/p>\n<p>In the <code>setup_with_4_items<\/code> method, it will create a <code>HashSet<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>allow_null<\/code> method, it will add a <code>null<\/code> object.<\/p>\n<p>In the <code>Set_no_duplicate<\/code> method, it will show that <code>Set<\/code> does not allow any duplicate elements.<\/p>\n<p><span style=\"text-decoration: underline\"><em>HashSet_POJOTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.HashSet;\nimport java.util.Set;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\nimport jcg.zheng.demo.data.SomeData;\n\npublic class HashSet_POJOTest extends CollectionBase_POJOTest {\n\n @Test\n public void allow_null() {\n Set&lt;SomeData&gt; setData = new HashSet&lt;&gt;();\n setData.add(null);\n assertEquals(1, setData.size());\n }\n\n @Test\n public void Set_no_duplicate() {\n Set&lt;SomeData&gt; setData = new HashSet&lt;&gt;();\n\n setData.add(buildSomeData(1, \"Tom\"));\n setData.add(buildSomeData(3, \"Mary\"));\n setData.add(buildSomeData(2, \"Shan\"));\n setData.add(buildSomeData(2, \"Shan\"));\n setData.add(buildSomeData(4, \"Zheng\"));\n assertEquals(4, setData.size());\n\n }\n\n @Before\n public void setup_with_4_items() {\n logger = LoggerFactory.getLogger(this.getClass());\n\n list = new HashSet&lt;SomeData&gt;();\n assertTrue(list.isEmpty());\n\n list.add(buildSomeData(1, \"Item1\"));\n assertEquals(1, list.size());\n list.add(buildSomeData(2, \"Item2\"));\n assertEquals(2, list.size());\n list.add(buildSomeData(3, \"Item3\"));\n assertEquals(3, list.size());\n list.add(buildSomeData(4, \"Item4\"));\n assertEquals(4, list.size());\n }\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=HashSet_POJOTest<code><\/code><\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.HashSet_POJOTest\n05:30:28.475 [main] INFO jcg.zheng.demo.HashSet_POJOTest - The arraylist contains the following elements: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4], SomeData [name=test, id=1]]\n05:30:28.488 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Retrieving items using for loop\n05:30:28.489 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:30:28.489 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:30:28.489 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:30:28.490 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:30:28.491 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Retrieving items using Java 8 Stream\n05:30:28.494 [main] INFO jcg.zheng.demo.HashSet_POJOTest - SomeData [name=Item1, id=1]\n05:30:28.496 [main] INFO jcg.zheng.demo.HashSet_POJOTest - SomeData [name=Item2, id=2]\n05:30:28.497 [main] INFO jcg.zheng.demo.HashSet_POJOTest - SomeData [name=Item3, id=3]\n05:30:28.497 [main] INFO jcg.zheng.demo.HashSet_POJOTest - SomeData [name=Item4, id=4]\n05:30:28.498 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Retrieving items using iterator\n05:30:28.500 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:30:28.500 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:30:28.500 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:30:28.500 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:30:28.502 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Retrieving items using iterator\n05:30:28.503 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:30:28.504 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:30:28.504 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:30:28.505 [main] INFO jcg.zheng.demo.HashSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:30:28.508 [main] INFO jcg.zheng.demo.HashSet_POJOTest - The array created after the conversion of our arraylist is: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4]]\nTests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.483 sec\n\nResults :\n\nTests run: 12, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  10.608 s\n[INFO] Finished at: 2019-08-04T05:30:28-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-5-7-treeset-pojotest\">5.7 TreeSet_POJOTest<\/h3>\n<p><a aria-label=\"TreeSet (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/TreeSet.html\" target=\"_blank\">TreeSet<\/a> extends from <a aria-label=\"AbstractSet (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/docs\/api\/java.base\/java\/util\/AbstractSet.html\" target=\"_blank\">AbstractSet<\/a> which implements the Java Set interface. Objects in a <code>TreeSet<\/code> are stored in a sorted and ascending order.<\/p>\n<p>In this step, I will create a <code>TreeSet_POJOTest<\/code> class which extends from <code>CollectionBase_POJOTest<\/code>.<\/p>\n<p>In the <code>setup_with_4_items<\/code> method, it will create a <code>TreeSet<\/code> instance and add four items. This method is also annotated with <code>@Before<\/code> annotation so it will be called for each test method.<\/p>\n<p>In the <code>Set_no_duplicate_ordered<\/code> method, it will show that <code>TreeSet<\/code> orders its unique elements.<\/p>\n<p><span style=\"text-decoration: underline\"><em>TreeSet_POJOTest.java<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:java\">package jcg.zheng.demo;\n\nimport static org.junit.Assert.assertEquals;\nimport static org.junit.Assert.assertTrue;\n\nimport java.util.Set;\nimport java.util.TreeSet;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.slf4j.LoggerFactory;\n\nimport jcg.zheng.demo.data.SomeData;\n\npublic class TreeSet_POJOTest extends CollectionBase_POJOTest {\n\n\t@Test\n\tpublic void Set_no_duplicate_ordered() {\n\t\tSet&lt;SomeData&gt; testSet = new TreeSet&lt;&gt;();\n\n\t\ttestSet.add(buildSomeData(1, \"Tom\"));\n\t\ttestSet.add(buildSomeData(3, \"Mary\"));\n\t\ttestSet.add(buildSomeData(2, \"Shan\"));\n\t\ttestSet.add(buildSomeData(2, \"Shan\"));\n\t\ttestSet.add(buildSomeData(4, \"Zheng\"));\n\t\tassertEquals(4, testSet.size());\n\n\t\tlogger.info(\"TreeSet is ordered\");\n\t\ttestSet.forEach(item -&gt; {\n\t\t\tlogger.info(item.toString());\n\t\t});\n\n\t}\n\n\t@Before\n\tpublic void setup_with_4_items() {\n\t\tlogger = LoggerFactory.getLogger(this.getClass());\n\n\t\tlist = new TreeSet&lt;SomeData&gt;();\n\t\tassertTrue(list.isEmpty());\n\n\t\tlist.add(buildSomeData(1, \"Item1\"));\n\t\tassertEquals(1, list.size());\n\t\tlist.add(buildSomeData(2, \"Item2\"));\n\t\tassertEquals(2, list.size());\n\t\tlist.add(buildSomeData(3, \"Item3\"));\n\t\tassertEquals(3, list.size());\n\t\tlist.add(buildSomeData(4, \"Item4\"));\n\t\tassertEquals(4, list.size());\n\t}\n\n}\n<\/pre>\n<p>Execute <code>mvn test -Dtest=TreeSet_POJOTest<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:bash\">-------------------------------------------------------\n T E S T S\n-------------------------------------------------------\nRunning jcg.zheng.demo.TreeSet_POJOTest\n05:31:47.416 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - TreeSet is ordered\n05:31:47.472 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Mary, id=3]\n05:31:47.472 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Shan, id=2]\n05:31:47.472 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Tom, id=1]\n05:31:47.473 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Zheng, id=4]\n05:31:47.499 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - The arraylist contains the following elements: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4], SomeData [name=test, id=1]]\n05:31:47.504 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Retrieving items using for loop\n05:31:47.507 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:31:47.508 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:31:47.508 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:31:47.508 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:31:47.511 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Retrieving items using Java 8 Stream\n05:31:47.514 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Item1, id=1]\n05:31:47.515 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Item2, id=2]\n05:31:47.515 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Item3, id=3]\n05:31:47.516 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - SomeData [name=Item4, id=4]\n05:31:47.517 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Retrieving items using iterator\n05:31:47.518 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:31:47.518 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:31:47.518 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:31:47.519 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:31:47.520 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Retrieving items using iterator\n05:31:47.522 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item1, id=1]\n05:31:47.522 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item2, id=2]\n05:31:47.523 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item3, id=3]\n05:31:47.523 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - Item is: SomeData [name=Item4, id=4]\n05:31:47.528 [main] INFO jcg.zheng.demo.TreeSet_POJOTest - The array created after the conversion of our arraylist is: [SomeData [name=Item1, id=1], SomeData [name=Item2, id=2], SomeData [name=Item3, id=3], SomeData [name=Item4, id=4]]\nTests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.489 sec\n\nResults :\n\nTests run: 11, Failures: 0, Errors: 0, Skipped: 0\n\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  11.171 s\n[INFO] Finished at: 2019-08-04T05:31:47-05:00\n[INFO] ------------------------------------------------------------------------\n\nC:\\MaryZheng\\Workspaces\\jdk12\\java-collections-demo&gt;<\/pre>\n<h2 class=\"wp-block-heading\" id=\"h-6-summary\">6. Summary<\/h2>\n<p>In this article, I covered the fundamental&nbsp;of Java Collections framework, which is part of the core java skillset. I created several test classes to demonstrate how to add, remove, retrieve, clear, sort, and search items from a collection of objects.<\/p>\n<p>Please check <a aria-label=\"here  (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/www.bigocheatsheet.com\/\" target=\"_blank\">here <\/a>for more details about the Big-O differences among these interfaces and classes in the Java collection framework.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-7-related-articles\">7. Related articles<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/arraylist-java-example\/\">ArrayList Java Example \u2013 How to use arraylist<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-8-download-the-source-code\">8. Download the Source Code<\/h2>\n<p>This example consists of Maven project to demonstrate the Collections framework, which is part of the core java skillset.  <\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/java-collections-demo.zip\"><strong>Java Collections Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction A collection is a group of objects and treated as a single unit. It is used to store, retrieve, and manipulate aggregate data. Collections are part of the core java and all java developers must have familiarity with them. Java has provided a collection framework which contains interfaces, classes, and algorithms since version &hellip;<\/p>\n","protected":false},"author":140,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-75337","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Collections Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Collections Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-09T08:00:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-07T12:59:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae\"},\"headline\":\"Java Collections Tutorial\",\"datePublished\":\"2019-08-09T08:00:57+00:00\",\"dateModified\":\"2022-07-07T12:59:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\"},\"wordCount\":1085,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\",\"name\":\"Java Collections Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2019-08-09T08:00:57+00:00\",\"dateModified\":\"2022-07-07T12:59:02+00:00\",\"description\":\"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java Collections Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mary-zheng\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Collections Tutorial - Java Code Geeks","description":"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Java Collections Tutorial - Java Code Geeks","og_description":"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.","og_url":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-08-09T08:00:57+00:00","article_modified_time":"2022-07-07T12:59:02+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/"},"author":{"name":"Mary Zheng","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae"},"headline":"Java Collections Tutorial","datePublished":"2019-08-09T08:00:57+00:00","dateModified":"2022-07-07T12:59:02+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/"},"wordCount":1085,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/","name":"Java Collections Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2019-08-09T08:00:57+00:00","dateModified":"2022-07-07T12:59:02+00:00","description":"Check out our detailed example on Java Collections, a core java skill! The most important interfaces are Java Set, Map, and List which extend the Collection interface.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-collections-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"Java Collections Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg","caption":"Mary Zheng"},"description":"Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.","url":"https:\/\/examples.javacodegeeks.com\/author\/mary-zheng\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/75337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/140"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=75337"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/75337\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=75337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=75337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=75337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}