Collections

  • Not fixed in size, that is growable in nature.
  • Can hold heterogeneous objects as well as homogeneous objects.
  • Every collection class is based on some standard data structure.
  • Collections are more performance expensive.
  • Collection can hold only objects, but not primitive.
  • Collection is a group of individual objects as a single entity
  • Collection framework defines several classes and interfaces that can be used to represent collection and perform operations on it.
  • Key interfaces in collection framework are
    • Collection
      • Defines the most common methods Of collection framework like contains, empty, add, remove, et cetera
      • Collection interface is considered as root interface of collection framework.
      • There is no concrete class which implements collection interface directly.
      • Collection versus Collections
        • Collection is an interface. Collections is a class.
        • Collection is a root interface of collection framework. Collections is a utility class Which defines several utility methods for collection object like sort.
        • Collection interface can be used to represent a group of individual objects as a single entity.
    • List interface
      • Duplicate are allowed
      • Insertion order is preserved
      • Implementation classes are
        • ArrayList
        • LinkedList
        • Vector
          • Stack
      • Vector and stack are also called as legacy classes as they came in 1.0 version.
      • List is a child interface of collection
    • Set interface
      • Duplicates are not allowed
      • Insertion order is not maintained
      • Implementation classes are
        • Hash set
          • Linked hash set
      • Set a child interface of collection
    • Sorted set interface
      • Sorted set is the child interface of Set interface
      • If we want to represent a group of individual objects as a single entity, where duplicates are not allowed, but all objects are sorted According to some sorting order, then we should go for sorted set.
    • Navigable Set
      • It is a child interface of sorted set
      • Implementation class is
        • TreeSet
      • Define methods for navigation purposes
    • Queue
      • Represents a group of objects prior to processing In first in first out manner.
      • Implementation classes are
        • Priority Queue
        • Blocking Queue
          • Linked blocking Queue
            • Priority blocking queue
    • Map Interface
      • All the before interfaces, are meant for representing a group of individual objects.
      • If we want to represent a group of objects as key value pairs, then we should go for a map interface.
      • It is not a child interface of collection
      • Duplicate keys are not allowed
      • Duplicate values are allowed
      • Implementation classes are
        • Hashmap
          • Linked Hashmap
        • Weak Hashmap
        • Identity Hashmap
        • Hash table
          • Properties
          • Has table is the child of Dictionary.
          • Hashtable is a legacy class
    • Sorted map interface
      • When we want to represent a group of values As key value pairs according to sorted value of keys.
      • It is the child interface of map interface.
    • Navigable map
      • Child interface of sorted map.
      • Defines navigation functions for sorted map
      • Implementation classes are
        • Treemap
  • ArrayList
    • ArrayList Is implemented with concept of dynamic array.
    • In ArrayList Addition and removal of element takes O(n) notation And is expensive. Searching is, however, not expensive.
  • LinkedList
    • In linked list, the implementation is with the concept of double Link list.
    • In link, list, addition and removal is in expensive, but searching for an element or traversing a node is expensive.
  • Hashmap
    • There are unique keys
    • o(1) Operation for search, insert, and delete
    • Maps, larger values to smaller values
    • Should uniformly distribute large keys into a hash table slot
    • Algorithm used
      • For large keys, use modular algorithm
      • For string keys Use weight Sum
      • For objects Use weighted sum of elements
    • The default, bucket size of Java hash map is 16
    • Once the link list length, which is eight, then it is converted to a self balancing binary tree.
  • Equals and hash code contract

No comments:

Post a Comment