OOP1_Unit 11 (Amiraj) VisionPapers.in
OOP1_Unit 11 (Amiraj) VisionPapers.in
-PREPARED BY
SUBJECT:OOP-I PREPARED BY:
CODE:3140705 ASST.PROF.NENSI KANSAGARA PROF.NENSI KANSAGARA
(CSE DEPARTMENT,ACET)
SETS:
Set is an unordered collection, it doesn’t maintain any order. There are few
implementations of Set which maintains the order such as LinkedHashSet (It
maintains the elements in insertion order).
2) List allows duplicates while Set doesn’t allow duplicate elements. All the
elements of a Set should be unique if you try to insert the duplicate element in
Set it would replace the existing value.
3) List implementations: ArrayList, LinkedList etc.
4) List allows any number of null values. Set can have only a single null
value at most.
6) List interface has one legacy class called Vector whereas Set interface
does not have any legacy class.
SINGLETON AND UNMODIFIED COLLECTION:
This class implements a hash table, which maps keys to values. Any
non-null object can be used as a key or as a value. Hashtable is similar
to HashMap except it is synchronized.
Java HashMap class implements the map interface by using a hash table. It inherits
AbstractMap class and implements Map interface.
Points to remember
❖ Java HashMap class contains values based on the key.
❖ Java HashMap class contains only unique keys.
❖ Java HashMap class may have one null key and multiple null values.
❖ Java HashMap class is non synchronized.
❖ Java HashMap class maintains no order.
❖ The initial default capacity of Java HashMap class is 16 with a load factor of 0.75.
Methods for HashMap
DIFFERENCE BETWEEN HASHTABLE AND
HASHMAP
TREEMAP
❖ Java TreeMap contains values based on the key. It implements the NavigableMap
interface and extends AbstractMap class.
❖ Java TreeMap contains only unique elements.
❖ Java TreeMap cannot have a null key but can have multiple null values.
❖ Java TreeMap is non synchronized.
❖ Java TreeMap maintains ascending order.
public class TreeMap<K,V> extends AbstractMap<K,V> implements
NavigableMap<K,V>