tag:blogger.com,1999:blog-8712770457197348465.post8994854601672355307..comments2024-03-29T00:43:22.798-07:00Comments on Javarevisited: Top 25 Java Collection Framework Interview Questions Answers for Freshers and Experienced Programmersjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger30125tag:blogger.com,1999:blog-8712770457197348465.post-15824087077267216102020-12-05T05:12:47.922-08:002020-12-05T05:12:47.922-08:00Poll() method returns null incase que is empty
rem...Poll() method returns null incase que is empty<br />remove() method returns NoSuchElementExceptionAnonymoushttps://www.blogger.com/profile/01223905295675571192noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-80747263295028834852020-02-01T06:38:50.331-08:002020-02-01T06:38:50.331-08:00Hello Rita, they don't extend Collection direc...Hello Rita, they don't extend Collection directly instead there is an intermediate class like AbstractList which implement all method of Collection and then ArrayList just overrides them as per their need. Similarly you have AbstractSet class. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18423201741602384172020-02-01T02:17:30.135-08:002020-02-01T02:17:30.135-08:00I have one confusion, if ArrayList,HashSet impleme...I have one confusion, if ArrayList,HashSet implements Collection Interface, why they does not implement all the methods defined as part of collection as per normal class functionality i.e if a class implements any interface, it should implement all its methods or it should be abstract. Any concrete class will implements all the methods of interfaceRitahttps://www.blogger.com/profile/00180905697886084981noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-77008447572775335002019-09-01T12:01:42.817-07:002019-09-01T12:01:42.817-07:00when to use identityhashmap?when to use identityhashmap?Anonymoushttps://www.blogger.com/profile/16675858048687460717noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-77872970331407296552018-08-26T06:24:40.541-07:002018-08-26T06:24:40.541-07:00 In 19, there is no added() method in ListIterat... In 19, there is no added() method in ListIterator but add() method...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89811445663320946572017-02-18T20:10:57.690-08:002017-02-18T20:10:57.690-08:00Hello @Anonymous, HashMap allows duplicate values,...Hello @Anonymous, HashMap allows duplicate values, it doesn't allow duplicate key, hence it is possible to store same values for all the keys and HashSet just does that. I suggest you reading my another article <a href="http://www.java67.com/2014/01/how-hashset-is-implemented-or-works-internally-java.html" rel="nofollow">How HashSet internally works in Java</a> to get some more insights. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-50569549103414485742017-02-18T12:58:24.347-08:002017-02-18T12:58:24.347-08:00Hi Javin,Great work,your blog is the best way to b...Hi Javin,Great work,your blog is the best way to brush up concepts.Thank you.<br />Hope you answer my question here.Hashset internally stores it's values like HashMap with equal value for all keys right?How can HashMap have duplicate key values?Am I missing something here?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-29750810564806412112016-02-06T01:17:30.187-08:002016-02-06T01:17:30.187-08:00@Mehrdad, you are right in case of remove(int i) o...@Mehrdad, you are right in case of remove(int i) or remove(object) method, both of which requires traversal to the right element, but if you simply call the remove() method on LinkedList, it removes elements from head which is O(1) because LinkedList maintains reference of head or first element. You can see the code in java.util.LinkedList class that remove() calls the removeFirst() which just javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21317723540729320402016-02-05T13:41:18.317-08:002016-02-05T13:41:18.317-08:00In the list given in response to question 18, the ...In the list given in response to question 18, the complexity of the remove() operation for a LinkedList is displayed as O(1) while get() is listed as O(n). <br /><br />In java.util.LinkedList implementation, both remove() and get() operations rely on entry(i) call to navigate the linked list to get to the element at index "i".Mehrdadhttps://www.blogger.com/profile/11085026681304145513noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-64870906549177118732015-12-11T03:28:36.864-08:002015-12-11T03:28:36.864-08:009. The difference between HashMap and Hashtable? (...9. The difference between HashMap and Hashtable? (answer)<br />This is another Classical Java Collection interview asked on beginner’s level and most of Java developer has a predefined answer for this interview questions e.g. HashMap is not synchronized while Hashtable is not or hashmap is faster than hash table etc. What could go wrong is that if he placed another follow-up question like how Anonymoushttps://www.blogger.com/profile/00058990956705027960noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-83650993421679342912015-10-21T19:38:17.246-07:002015-10-21T19:38:17.246-07:00Fantastic questions form Java collections topic, b...Fantastic questions form Java collections topic, but see this list of Java interview questions from last 5 years to prepare all other topics, see <a href="http://javarevisited.blogspot.com/2015/10/133-java-interview-questions-answers-from-last-5-years.html" rel="nofollow">the list </a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2983871772823234412015-10-21T19:31:50.608-07:002015-10-21T19:31:50.608-07:00Great list of questions, for more Java interview q...Great list of questions, for more Java interview questions from last 5 years, see this list of <a href="http://javarevisited.blogspot.com/2015/10/133-java-interview-questions-answers-from-last-5-years.html" rel="nofollow">133 Java questions with answers</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43882765485251166412015-10-16T04:42:01.145-07:002015-10-16T04:42:01.145-07:00when I tried the below code I got exception mentio...when I tried the below code I got exception mentioned in the code. Please clarify me why I got exception. Is there any relation between trimsize() and sublist() methods of arrayList<br /><br /> Public class Practice<br />{<br /> Public static void main()<br /> {<br /> ArrayList pArrayList = new ArrayList(50);<br /> <br /> pArrayList.add("PXXXXXX");<br /> pArrayList.add(&Prabhakarhttps://www.blogger.com/profile/11420206622254627104noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26624655092283023562015-09-30T05:58:56.173-07:002015-09-30T05:58:56.173-07:00@Arturs didn't get your point. HashSet does us...@Arturs didn't get your point. HashSet does use HashMap internally and same value, an object is used for all keys. In short, HashMap's key set is your HashSet. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54597404282946425112015-09-30T02:04:49.712-07:002015-09-30T02:04:49.712-07:00it uses a HashMap with same values for all keys - ...it uses a HashMap with same values for all keys - Maybe you meant for values, but not for keys?Anonymoushttps://www.blogger.com/profile/07647386478202434676noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-11323445505347068392015-08-26T23:29:05.708-07:002015-08-26T23:29:05.708-07:00Hi Nice article. Requesting one modification in qu...Hi Nice article. Requesting one modification in question 21. you have written "Map doesn't implement Collection interface" it should be "Map doesn't extends Collection interface".<br />Anonymoushttps://www.blogger.com/profile/12226386942689056343noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89977780030042402422015-04-01T04:16:40.586-07:002015-04-01T04:16:40.586-07:00post the internal implementation of ArrayList i w...post the internal implementation of ArrayList i will be grateful to you....<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-4663162144943738592014-09-04T21:13:54.917-07:002014-09-04T21:13:54.917-07:00The key also has to be immutable.. The key also has to be immutable.. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-55048180465498080962014-06-26T11:39:00.903-07:002014-06-26T11:39:00.903-07:00Recently I was asked the difference between a link...Recently I was asked the difference between a linkedHashMap and a PriorityQueue.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56064018704764061732013-09-25T12:41:30.957-07:002013-09-25T12:41:30.957-07:00" If you have equaled number of reader and wr..." If you have equaled number of reader and writer than ConcurrentHashMap will perform in line of hashtable or synchronized hashMap."<br />If you have equaled number of reader and writer than ConcurrentHashMap will perform n times better, where n will be somewhere close to number of cpu cores. Not whole ConcurrentHashMap is blocked on writes, but only some part of it. There is mechanism Arkadiusz Głowackihttps://www.blogger.com/profile/15711077516639954555noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-62090997611956153692013-08-26T20:16:26.888-07:002013-08-26T20:16:26.888-07:00Hello Javin, Recently I was asked in a Java interv...Hello Javin, Recently I was asked in a Java interview about, what is difference between poll() and remove() method, if both are used to remove object from Queue. I get confused, because, poll() also removes elements from head and remove() is used to remove object, which is passed to it. Is there any other difference between poll and remove, from Queue or DeQue perspective, which interviewer was Gayatrinoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-62431893858833891122013-07-19T12:34:41.951-07:002013-07-19T12:34:41.951-07:00"HashMap is not synchronized while hashtalbe ..."HashMap is not synchronized while hashtalbe is not "<br /><br />I think you meant <br /><br />"HashMap is not synchronized while hashtalbe is"Srikanthhttps://www.blogger.com/profile/09760070151096261951noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-40316360366326332762013-04-30T19:26:30.035-07:002013-04-30T19:26:30.035-07:00Hello Javarevisited
Please do not give ...Hello Javarevisited<br /> Please do not give this is tricky interview question and all. we this tricky interview question that we know, please try to give solution and also give the solution in one page that's better.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24945194126581521042013-04-30T00:34:28.246-07:002013-04-30T00:34:28.246-07:00Hi Javin, Can you update this article to include s...Hi Javin, Can you update this article to include some more tough, less popular but difficult questions based on Java Collections asked to experienced Java programmers, e.g. this is the one questions asked to me on Citibank interview :<br /><br />How do you remove an entry from a Collection? and subsequently what is difference between remove() method of Collection and remove() method of Iterator, Mohitnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7806880571606419812013-04-16T20:11:05.580-07:002013-04-16T20:11:05.580-07:00One Java Collection Interview Question, which I ha...One Java Collection Interview Question, which I have faced more often in JP Morgan, Cognizant and HSBC recently :<br /><br />What do you need to do to use a custom object as key in Collection classes like Map or Set?<br /><br />Answer is : If you are using any custom object in Map as key, you need to override equals() and hashCode() method, and make sure they follow there contract. On the other Prateeknoreply@blogger.com