{"id":465,"date":"2022-11-01T15:52:49","date_gmt":"2022-11-01T07:52:49","guid":{"rendered":"https:\/\/islandtropicaman.com\/wp\/?p=465"},"modified":"2022-11-01T15:53:39","modified_gmt":"2022-11-01T07:53:39","slug":"create-generic-type-arraylist-in-java-program","status":"publish","type":"post","link":"https:\/\/islandtropicaman.com\/wp\/2022\/11\/01\/create-generic-type-arraylist-in-java-program\/","title":{"rendered":"Create generic type ArrayList in Java program"},"content":{"rendered":"<p>In this example, let us create a generic type ArrayList to read in a few type string values and then iterate through those string elements and print them out on the screen.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nList&lt;String&gt; greeting = new ArrayList&lt;String&gt;();\r\ngreeting.add(&quot;Hello&quot;);\r\ngreeting.add(&quot;world&quot;);\r\nIterator&lt;String&gt; greet = greeting.iterator();\r\nwhile(greet.hasNext()) {\r\n   System.out.println(greet.next());\r\n}\r\n<\/pre>\n<p>The above program will create the following outcomes:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nHello\r\nworld\r\n<\/pre>\n<p>There is no need to cast the return object from the next method of the Iterator<String> object as a type string object because the returned object is a string object after the creation of the type string Iterator! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example, let us create a generic type ArrayList to read in a few type string values and then iterate through those string elements and print them out on the screen. List&lt;String&gt; greeting = new ArrayList&lt;String&gt;(); greeting.add(&quot;Hello&quot;); greeting.add(&quot;world&quot;); Iterator&lt;String&gt; greet = greeting.iterator(); while(greet.hasNext()) { System.out.println(greet.next()); } The above program will create the following outcomes:&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"https:\/\/islandtropicaman.com\/wp\/2022\/11\/01\/create-generic-type-arraylist-in-java-program\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;Create generic type ArrayList in Java program&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137,138],"tags":[139,141,140],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-java","category-java-generic","tag-arraylist","tag-generic","tag-java"],"blog_post_layout_featured_media_urls":{"thumbnail":"","full":""},"categories_names":{"137":{"name":"Java","link":"https:\/\/islandtropicaman.com\/wp\/category\/java\/"},"138":{"name":"Java Generic","link":"https:\/\/islandtropicaman.com\/wp\/category\/java\/java-generic\/"}},"tags_names":{"139":{"name":"ArrayList","link":"https:\/\/islandtropicaman.com\/wp\/tag\/arraylist\/"},"141":{"name":"Generic","link":"https:\/\/islandtropicaman.com\/wp\/tag\/generic\/"},"140":{"name":"Java","link":"https:\/\/islandtropicaman.com\/wp\/tag\/java\/"}},"comments_number":"0","_links":{"self":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":1,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":466,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/posts\/465\/revisions\/466"}],"wp:attachment":[{"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/islandtropicaman.com\/wp\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}