What is the difference between set and map in java




















Skip to content. Ordering List represents an ordered sequence in Java whose elements are accessible by index. Null values List allows any number of null values while a set contains at most one null element.

When to use List, Set and Map? References: 1. Rate this post. We are sorry that this post was not useful for you! Tell us how we can improve this post? Submit Feedback. Thanks for reading. Like us? Hashtable doesn't allow null key or null values. ConcurrentHashMap doesn't allow null key or null values. ConcurrentSkipListMap doesn't allow null key or null values. Getting element on specific index.

List implementations provide get method to get element on specific index in java. Method returns element on specified index. Get method directly gets element on specified index. Hence, offering O 1 complexity. Set implementations does not provide any such get method to get element on specified index in java. Map implementations does not provide any such get method to get element on specified index in java. Implementing classes. Set does not provide anything like listIterator.

It simply return Iterator in java. Map provides three type of iterators -. Structure and resizable. List are Resizable-array implementation of the java. List interface in java. Set uses Map for their implementation. Hence, structure is map based and resizing depends on Map implementation. Map uses hashing technique for storing key-value pairs.

As ArrayList uses array for implementation it is index based structure, hence provides random access to elements. Collection API is huge and it's difficult to know every bits and piece but at the same time, there is no excuse for not knowing fundamentals like the difference between Set, List, and Map in Java. Thanks for reading this article so far. If you find this Java interview question interesting and my explanation useful then please share it with your friends and colleagues.

If you have you have any questions or feedback then please drop a note. Labels: core java , core java interview question answer , Java collection tutorial. Anonymous June 10, at PM. Anonymous September 8, at AM. Anonymous March 10, at PM. Anonymous April 21, at AM. Anonymous May 10, at AM.

Anonymous May 22, at PM. Anonymous June 3, at AM. Anonymous June 15, at AM. Anonymous October 8, at AM. Anonymous January 22, at PM. Anonymous June 7, at AM. Anonymous June 17, at PM. Anonymous June 29, at AM. Sagar June 30, at AM. Anonymous July 10, at AM. Unknown December 27, at PM. Unknown December 20, at AM. Anonymous March 1, at AM.

Basant Kumar May 7, at AM. Anonymous June 20, at AM. Unknown June 20, at PM. Anonymous October 18, at PM. Unknown August 29, at PM. Anonymous November 5, at AM. Felipe March 19, at AM.



0コメント

  • 1000 / 1000