23 June 2021

#Collections

Collections
What is the advantage of Properties file?
What is the advantage of the generic collection?
What is hash-collision ?
What is the default size of load factor in hashing based collection?
What is fail-fast ?
What is the difference between the length of an Array and size of ArrayList?
What is Classes ?
What is Interfaces ?
What is the main benefit of using the Properties file?
What is the need for overriding equals() method in Java?
What is the use of the List interface?
What is Singly Linked List?
What is Doubly Linked List?
What is Stack class?
What is key set view?
What is value set view?
What is entry set view?
What is Circular Queue?
What is Double-ended Queue?
What are the main differences between array and collection?
What are the advantages of the Collection Framework in Java?
What are the various methods provided by the Queue interface?
What do you understand by Collection Framework in Java?
What is BlockingQueue?
What is emptySet()?
What is dictionary class
What is Iterator()?
What is framework in Java?
What is the Collection framework in Java?
What is the hashCode()?
What is a Stack?
What are the benefits of the Collection Framework in Java?
What is a good way to sort the Collection objects in Java?
What are the two ways to remove duplicates from ArrayList?
What is IdentityHashMap?
What are the methods to make collection thread-safe?
What is the peek() of the Queue interface?
What are the important methods used in a linked list?
What are the various ways to iterate over a list?
What are the advantages of the stack?
What is Array?
What is ArrayList?
What is LinkedList?
What is HashMap?
What is Hashtable?
What is LinkedHashMap?
What is TreeMap?
What is HashSet? Methods?
What is LinkedHashSet?
What is TreeSet? Methods?
What is Comparable interface?
What is Comparator interface?
What is Iterator?
What is ListIterator?
What is Spliterator?
What is PriorityQueue?
What is PriorityBlockingQueue?
What is ArrayBlockingQueue?
What is LinkedTransferQueue?
What is CopyOnWriteArrayList?
What is CopyOnWriteArraySet?
What is ArrayDequeue?
What is ConcurrentLinkedQueue?
What is PriorirityBlockingQueue?
What is SynchronousQueue?
What is DelayQueue?
What is LinkedBlockingQueue ?
What is IdentityHashMap ?
What is WeakHashMap?
What is EnumMap?
What is ConcurrentHashMap?
What is unmodifiableCollection
What is ConcurrentSkipListMap?
What is EnumSet?
What is ConcurrentSkipListSet?
What is Collections Class
What is override equals() method
What is equals() with example
What is generic collection?
What is List interface?
What is Set interface?
What is Dequeue interface?
What is Map interface?
What is Big-O notation
What is map. entry In Map
What are the methods to remove elements from ArrayList
What is emptySet() method in the Collections framework?
What are methods provided by the Queue interface?
What is Vector?
What is UnsupportedOperationException
What are the design pattern followed by Iterator
What is diamond operator
What is randomaccess interface
What is deque Interface
What are the various types of queues in Java
Name the collection classes that gives random element access to its elements
Name the collection classes that implement random access interface
Explain the methods of iterator interface
Explain for each loop with example
Why Collection doesn’t extend the Cloneable and Serializable interfaces?
Why Map doesn’t extend the Collection Interface?
Which method is used to sort an array in ascending order?
How internally Hashset working?
How to synchronize List, Set and Map elements?
How to convert ArrayList to Array and Array to ArrayList?
How to make Java ArrayList Read-Only?
How to remove duplicates from ArrayList?
How to reverse ArrayList?
How to sort ArrayList in descending order?
How to synchronize ArrayList?
How to iterate map?
How to measure the performance of an ArrayList?
How to join multiple ArrayLists?
How hash-collision is handled in Java?
How many types of LinkedList does Java support?
How the Collection objects are sorted in Java?
How will you reverse an List?
How to convert ArrayList to Array and Array to ArrayList
When to use ArrayList and LinkedList?
Difference - HashSet vs TreeSet
Difference - HashSet and HashMap?
Difference - HashMap vs TreeMap?
Difference - Array vs ArrayList
Difference - Singly Linked List vs Doubly Linked List
Difference Iterator vs Enumeration?
Difference -Comparable vs Comparator
Difference - Failfast and Failsafe
Difference - Hashmap and Hashtable
Difference - Stack and Queue
Difference - Array and Stack
Difference - Queue vs Deque.
Difference - Set vs Map?
Difference List vs Set.
Difference - Collection vs Collections
Difference - Iterator vs ListIterator
Difference - ArrayList vs LinkedList
Difference - ArrayList and Vector
Can you add a null element into a TreeSet or HashSet?
Can you use any class as a Map key?
Give example to sort an array in dscending order
Give an example of Hashmap
List down the primary interfaces provided by Java Collections Framework?
List down the major advantages of the Generic Collection.
List various classes available in sets
List methods available in Java Queue interface
Mention the methods provided by Stack class
Tell me about Collection hierarchy
Topic Content
List
  • ArrayList
    • It can contain duplicate elements.
    • It maintains insertion order.
    • It is non synchronized.
    • It allows random access because the array works on an index basis.
    • Manipulation is a little bit slower than the LinkedList because a lot of shifting needs to occur if any element is removed from the array list.
  • LinkedList
    • It can contain duplicate elements.
    • It maintains insertion order.
    • It is non synchronized.
    • Manipulation is fast because no shifting needs to occur.
    • It can be used as a list, stack or queue.
  • Vector
    • Vector is synchronized.
    • Java Vector contains many legacy methods that are not the part of a collections framework.
  • CopyOnWriteArraylist
Set
  • Hashset
    • It stores the elements by using a mechanism called hashing.
    • It contains unique elements only.
    • It allows null value.
    • It class is non synchronized.
    • It doesn't maintain the insertion order. Here, elements are inserted on the basis of their hashcode.
    • It is the best approach for search operations.
    • The initial default capacity of HashSet is 16, and the load factor is 0.75.
  • Linkedhashset
    • It contains unique elements only like HashSet.
    • It provides all optional set operations and permits null elements.
    • It is non-synchronized.
    • It maintains insertion order.
  • Treeset
    • It contains unique elements only like HashSet.
    • It access and retrieval times are quiet fast.
    • It doesn't allow null element.
    • It is non synchronized.
    • It maintains ascending order.
    • It contains unique elements only like HashSet.
    • It access and retrieval times are quite fast.
    • It doesn't allow null elements.
    • It is non-synchronized.
    • The TreeSet can only allow those generic types that are comparable. For example The Comparable interface is being implemented by the StringBuffer class.
Map
  • TreeMap
    • It contains values based on the key. It implements the NavigableMap interface and extends AbstractMap class.
    • It contains only unique elements.
    • It cannot have a null key but can have multiple null values.
    • It is non synchronized.
    • It maintains ascending order.
  • HashMap
    • It contains values based on the key.
    • It contains only unique keys.
    • It may have one null key and multiple null values.
    • It is non synchronized.
    • It maintains no order.
    • The initial default capacity of Java HashMap class is 16 with a load factor of 0.75.
  • Hashtable
    • A Hashtable is an array of a list. Each list is known as a bucket. The position of the bucket is identified by calling the hashcode() method. A Hashtable contains values based on the key.
    • Java Hashtable class contains unique elements.
    • Java Hashtable class doesn't allow null key or value.
    • Java Hashtable class is synchronized.
    • The initial default capacity of Hashtable class is 11 whereas loadFactor is 0.75.
  • ConCurrentHashmap
Other
  • Comparable
    • Comparable provides a single sorting sequence
    • It affects the original class,
    • It present in java.lang package.
    • Collections.sort(List).
  • Comparator
    • The Comparator provides multiple sorting sequences
    • Doesn't affect the original class
    • It present in java.util package.
    • Collections.sort(List, Comparator)
  • Iterator
    • By Iterator interface.
    • By for-each loop.
    • By ListIterator interface.
    • By for loop.
    • By forEach() method.
    • By forEachRemaining() method.

Duplicate Insertion order Sorted by natural order Synchronized Null elements Iterator
ArrayList Yes Yes Yes Fail-fast
LinkedList Yes Yes Yes Fail-fast
CopyOnWriteArrayList Yes Yes Yes Yes Fail-safe
HashSet Yes Fail-fast
LinkedHashSet Yes Yes Fail-fast
TreeSet Yes No Fail-fast
ConcurrentSkipListSet Yes Yes No Fail-safe
HashMap 1 null key & many null values Fail-fast
Hashtable Yes No Fail-fast
ConcurrentHashMap Yes No Fail-safe
TreeMap Yes Null key not allowed, Allow many null values Fail-fast
ConcurrentSkipListMap Yes Yes No Fail-safe

No comments:

Post a Comment

Most views on this month