tag:blogger.com,1999:blog-8712770457197348465.post2223066393385228128..comments2024-03-29T03:17:04.645-07:00Comments on Javarevisited: 10 Examples of HashSet in Java - Tutorialjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8712770457197348465.post-41300506350731361022016-11-27T23:04:59.501-08:002016-11-27T23:04:59.501-08:00import java.util.HashSet;
import java.util.Set;
pu...import java.util.HashSet;<br />import java.util.Set;<br />public class TestHashSet {<br /> //check heading : How to convert HashSet into array : its error<br /><br /> public static void main(String[] args) {<br /> Set set = new HashSet();<br /> set.add("1");<br /> set.add("2");<br /> set.add("3");<br /> set.add("4");<br /> set.add("5");<br /Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51774195461467064702016-01-24T07:54:24.151-08:002016-01-24T07:54:24.151-08:00System.out.println(set.size()); // Result is 1
Sys...System.out.println(set.size()); // Result is 1<br />System.out.println(set1.size()); // Result is 2<br /><br /><br />As String is immutable and use string pool concept, so hashmap handles differently in case of String for generating hashcode.<br /><br /> final int hash(Object k) {<br /> int h = hashSeed;<br /> if (0 != h && k instanceof String) {<br /> return vijayhttps://www.blogger.com/profile/13264931855613452969noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41513797034071221922015-11-29T23:09:29.802-08:002015-11-29T23:09:29.802-08:00Why set is not adding different String objects wit...Why set is not adding different String objects with same value.? While in case of other objects its allowing adding of duplicates. Please look at the below sample code and explain : <br /><br />public class Test {<br /> public static void main( String[] args ) {<br /> Set set = new HashSet ();<br /> String a = new String("A");<br /> String b = new String("A"Anonymoushttps://www.blogger.com/profile/04058041636426309226noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18102488960887984532015-10-04T11:42:10.843-07:002015-10-04T11:42:10.843-07:00see in Hashset the insertion order is not preserve...see in Hashset the insertion order is not preserved!!! so output will come in random order!!Anonymoushttps://www.blogger.com/profile/09257249379324378644noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-31073444086693399992015-10-03T04:18:50.088-07:002015-10-03T04:18:50.088-07:00import java.util.*;
public class HashSetDemo {
...import java.util.*;<br /><br />public class HashSetDemo {<br /><br /> public static void main(String args[]) {<br /> // create a hash set<br /> HashSet hs = new HashSet();<br /> // add elements to the hash set<br /> hs.add("B");<br /> hs.add("A");<br /> hs.add("D");<br /> hs.add("E");<br /> hs.add("C");<brAnonymoushttps://www.blogger.com/profile/18141297396685779128noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-46895088323726212172013-06-04T18:16:20.482-07:002013-06-04T18:16:20.482-07:00While you might have great capabilities, and knowl...While you might have great capabilities, and knowledge of Java per se, unfortunate as it is, I am unable to connect your thought process (as regards to the data structures in computer science) into logical statements as explained. <br /><br />Can you kindly do something about this in a way that the thoughts flow freely from a good teacher like you (who has a good grasp but...)<br /><br />Thanks Venkyshttps://www.blogger.com/profile/04851427900328714272noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86838122049946328442013-03-27T08:10:32.489-07:002013-03-27T08:10:32.489-07:00sir,
can you tell me how HshSet works internally.
...sir,<br />can you tell me how HshSet works internally.<br /><br />there is no key for store it in a bucket<br />then how HashSet store element internally..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68643803515664805362012-07-17T00:12:36.427-07:002012-07-17T00:12:36.427-07:00Which one is faster between HashSet and ArrayList ...Which one is faster between HashSet and ArrayList ?Anonymousnoreply@blogger.com