{"id":1251,"date":"2022-02-26T06:51:32","date_gmt":"2022-02-26T06:51:32","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1251"},"modified":"2022-02-26T06:51:32","modified_gmt":"2022-02-26T06:51:32","slug":"collection-interface","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/02\/26\/collection-interface\/","title":{"rendered":"Collection Interface"},"content":{"rendered":"\n<p>In this tutorial, we will learn about the Java Collection interface and its subinterfaces.<\/p>\n\n\n\n<p>The&nbsp;<code>Collection<\/code>&nbsp;interface is the root interface of the Java collections framework.<\/p>\n\n\n\n<p>There is no direct implementation of this interface. However, it is implemented through its subinterfaces like&nbsp;<code>List<\/code>,&nbsp;<code>Set<\/code>, and&nbsp;<code>Queue<\/code>.<\/p>\n\n\n\n<p>For example, the&nbsp;<code>ArrayList<\/code>&nbsp;class implements the&nbsp;<code>List<\/code>&nbsp;interface which is a subinterface of the&nbsp;<code>Collection<\/code>&nbsp;Interface.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.programiz.com\/sites\/tutorial2program\/files\/Java-collection-interface.png\" alt=\"Java Collection Interface and its subinterfaces.\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"subinterfaces\">Subinterfaces of Collection<\/h2>\n\n\n\n<p>As mentioned above, the&nbsp;<code>Collection<\/code>&nbsp;interface includes subinterfaces that are implemented by various classes in Java.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. List Interface<\/h3>\n\n\n\n<p>The\u00a0<code>List<\/code>\u00a0interface is an ordered collection that allows us to add and remove elements like an array.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Set Interface<\/h3>\n\n\n\n<p>The\u00a0<code>Set<\/code>\u00a0interface allows us to store elements in different sets similar to the set in mathematics. It cannot have duplicate elements.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Queue Interface<\/h3>\n\n\n\n<p>The\u00a0<code>Queue<\/code>\u00a0interface is used when we want to store and access elements in\u00a0<strong>First In, First Out(FIFO)<\/strong>\u00a0manner.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"methods\">Methods of Collection<\/h2>\n\n\n\n<p>The&nbsp;<code>Collection<\/code>&nbsp;interface includes various methods that can be used to perform different operations on objects. These methods are available in all its subinterfaces.<\/p>\n\n\n\n<ul><li><code>add()<\/code>&nbsp;&#8211; inserts the specified element to the collection<\/li><li><code>size()<\/code>&nbsp;&#8211; returns the size of the collection<\/li><li><code>remove()<\/code>&nbsp;&#8211; removes the specified element from the collection<\/li><li><code>iterator()<\/code>&nbsp;&#8211; returns an iterator to access elements of the collection<\/li><li><code>addAll()<\/code>&nbsp;&#8211; adds all the elements of a specified collection to the collection<\/li><li><code>removeAll()<\/code>&nbsp;&#8211; removes all the elements of the specified collection from the collection<\/li><li><code>clear()<\/code>&nbsp;&#8211; removes all the elements of the collection<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn about the Java Collection interface and its subinterfaces. The&nbsp;Collection&nbsp;interface is the root interface of the Java collections framework. There is no direct implementation of this interface. However, it is implemented through its subinterfaces like&nbsp;List,&nbsp;Set, and&nbsp;Queue. For example, the&nbsp;ArrayList&nbsp;class implements the&nbsp;List&nbsp;interface which is a subinterface of the&nbsp;Collection&nbsp;Interface. Subinterfaces of Collection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[584],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1251"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1251\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}