tag:blogger.com,1999:blog-694855878384792308.post5945029766317037510..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Difference between ArrayList and HashSet in Java? Answer with Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-694855878384792308.post-84855670256363418382020-10-22T00:23:21.654-07:002020-10-22T00:23:21.654-07:00just use HashSet if you dont wanna have any duplic...just use HashSet if you dont wanna have any duplicated dataAssegdhttps://www.blogger.com/profile/15473003966251284940noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-71112581702603728022018-04-22T23:44:30.172-07:002018-04-22T23:44:30.172-07:00Just go with HashSetJust go with HashSetAnonymoushttps://www.blogger.com/profile/05931832497759624423noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-52012675841685529982017-09-29T06:41:43.095-07:002017-09-29T06:41:43.095-07:00If we don't have duplicate data then which one...If we don't have duplicate data then which one is better to use among ArrayList and HashSet? And why?Anonymoushttps://www.blogger.com/profile/16949985370944184736noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-24701490428582396012017-02-15T05:45:26.988-08:002017-02-15T05:45:26.988-08:00A major advantage of HashSet over ArrayList is tha...A major advantage of HashSet over ArrayList is that lookup via the contains method is O(1) vs O(n).<br />So for moderate to large data a HashSet contains will vastly outperform the ArrayList contains.<br />Mauro Zalloccohttps://www.blogger.com/profile/00702929719561059592noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-28089554329926041452016-08-23T05:00:19.722-07:002016-08-23T05:00:19.722-07:00if you add null to HashSet we will not get any Exc...if you add null to HashSet we will not get any Exception also you can add multiple null values only one null will be added as HashSet maintains the uniqueness<br />HashSet hs= new HashSet();<br /> hs.add("Laxmi");<br /> hs.add(null);<br /> hs.add(null);<br />O/p<br />[null, Laxmi]<br />Anonymoushttps://www.blogger.com/profile/12084925734030513435noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-16827290386097658002016-07-04T17:31:12.109-07:002016-07-04T17:31:12.109-07:00Another difference is that ArrayList allows to add...Another difference is that ArrayList allows to add null value where as HashSet will throw exception if null is added.Blue Sapphirehttps://www.blogger.com/profile/06273835623614814951noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-29350414288625435852016-07-01T00:44:41.859-07:002016-07-01T00:44:41.859-07:00Thannks... helpful :)
Thannks... helpful :)<br />Anonymoushttps://www.blogger.com/profile/06475838464784957516noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-56136374243148293272015-06-24T07:51:30.438-07:002015-06-24T07:51:30.438-07:00ThanksThanksAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-20102944700046902192015-02-26T00:53:27.520-08:002015-02-26T00:53:27.520-08:00Really useful thanks Really useful thanks Anonymousnoreply@blogger.com