- 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
- If two objects are equal according to the equals(object o) Method, then the hash code for both the object must be same(integer value)
- It is not necessary that if you have same hash code for two objects means those two objects are equal. This is collision.better has function prevents this.
- Whenever it is invoked on same object More than once during the execution of a Java application, the hash code method Must consistently return same integer.
- Example
- Introduction
- Installation
- Junit
- Arrays
- Classes
- Data Types
- Expressions
- Interfaces
- JDBC
- Loops
- OOPS
- Serializable
- Strings
- Constructors
- Package
- Java Servlets
- Deployment
- Logging
- JSP
- ANT
- Web Services and Sockets
- Struts
- JPA
- Object Injection
- Annotations
- Reflection API
- Static Blocks
- Java Native Interface (JNI)
- Multithreading
- Tomcat Server
- Java Web Toolkit(JWT)
- Archive Files
- EJB(Enterprise Java Beans)
- JConsole
- Memory Profiling
- Hashing
- Exceptions
- Java Map Interface
- Java 8
- Garbage Collection
- Java 11
- Collections
Collections
Subscribe to:
Posts (Atom)
-
What is the way to import only static members of a class? We can import using “import static packagename.classname.*” We can import using “i...
-
Q What is the difference between Array List and Linked List? Array List and Linked List both extend the List interface which extends Coll...
-
How do you detect a deadlock in a running Java program? We can use Jconsole to check for Deadlock which comes with JDK. There are also other...
No comments:
Post a Comment