tag:blogger.com,1999:blog-8712770457197348465.post4405266361034616768..comments2024-03-19T05:51:39.935-07:00Comments on Javarevisited: How to convert a List to Set in Java? ArrayList to HashSet Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8712770457197348465.post-71462194955910870092015-12-10T11:43:40.044-08:002015-12-10T11:43:40.044-08:00how to implement set using list ? Set shouldn'...how to implement set using list ? Set shouldn't be used.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37040857003629267952014-02-20T09:11:04.740-08:002014-02-20T09:11:04.740-08:00Adding more - Its always a great idea to check the...Adding more - Its always a great idea to check the list for null(if list is returned by a method or list items are supplied from another object), else you will encounter NPE while creating the HashSet instance.Pawankumarhttps://www.blogger.com/profile/01642260264821774994noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-70426886183171702142013-08-22T18:20:05.808-07:002013-08-22T18:20:05.808-07:00It's 4 if he printing companySet.size(). Howev...It's 4 if he printing companySet.size(). However, I think there is a typo still printing companies.size() which is 5<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-79754627338513509402012-05-23T22:57:41.583-07:002012-05-23T22:57:41.583-07:00ArrayList to HashSet conversion is my most preferr...ArrayList to HashSet conversion is my most preferred method to remove duplicates from collection if Insertion order is not concern, as insertion order gets lost when you copy elements form ArrayList to HashSet. if you still wants to use HashSet to remove duplicates and want to keep the insertion order of List than consider using LinkedHashSet.Bhartihttp://commons.apache.org/collections/noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82443291925849946402012-02-11T02:49:28.668-08:002012-02-11T02:49:28.668-08:00@Anonymous you are absolutely correct, Size must b...@Anonymous you are absolutely correct, Size must be four its a bug if you see carefully I am still printing size of list instead of size of hashset in Java. <br />companies.size() //size of list.<br />will correct it. thanks for pointing it out.Javin @ hashtable example javahttp://javarevisited.blogspot.com/2012/01/java-hashtable-example-tutorial-code.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7612308578890243962012-02-10T05:52:46.906-08:002012-02-10T05:52:46.906-08:00Size of HashSet after Converstion should be 4 if i...Size of HashSet after Converstion should be 4 if i am not mistaken.please correct me if i am wrong.<br />thanksAnonymousnoreply@blogger.com