The course is part of this learning path
In this course, we'll learn the Collection framework and the Map Interface.
- Collection Framework vs Array
- Hierarchy of Collection Framework
- List interface - ArrayList Class
- Iterator Interface
- Set Interface
- Queue and Dequeue Interfaces
- Map Interface
- Anyone looking to get Oracle Java Certification
- Those who want to learn the Java Programming language from scratch
- Java developers who want to increase their knowledge
- Beginners with no previous coding experience in Java programming
- Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams
- No prior knowledge is required about the Java programming language
- Basic computer knowledge
Hi there. In this lesson, we will talk about collections. In our previous lesson, we compared arrays and collections. In conclusion, we can say that collections are actually an alternative to arrays because we can handle a job that we cannot handle with arrays with the help of collections. The most important difference between them is that the size of collections is flexible while the size of arrays is fixed. Thanks to some methods offered in the collection framework, we can easily add, delete, or access data. So, what exactly is a collection?
How can we answer the question? A collection, sometimes called the container, is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate and communicate aggregate data. Typically, they represent data items that form a natural group such as a poker hand, a collection of cards, a mail folder, a collection of letters or a telephone directory, a mapping of names to phone numbers. Java Collection means a single unit of objects. The Java collection framework provides many interfaces such as Set, List, Queue, Deque, and classes such as ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, and TreeSet. Well, what is a collections framework? A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks can contain the following: Interfaces.
These are the abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of the representation. In object-oriented languages, interfaces generally form a hierarchy. Implementations. These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures. Algorithms. These are the methods that perform useful computations such as searching and sorting on objects that implement collection interfaces. The algorithms are said to be polymorphic. That is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality. Now let's look at the architecture of the collection interface. In the table on the slide, you can see the interfaces and classes available in the collection frame.
The blue boxes represent interface in the collection framework, while the brown boxes represent classes. Solid arrows show the inheritance or extending hierarchy between interfaces, while dashed arrows show which class implements which interface. At the top of the hierarchy is the collection interface and the core collection interfaces: List, Queue, Set, Deque, and SortedSet. That depend on it, our core collection interfaces. Let's briefly explain these core interfaces. Collection. The root of the collection hierarchy. A collection represents a group of objects known as it elements.
The collection interface is the least common denominator that all collections implement and is used to pass collections around and manipulate them when maximum generality is desired. Some types of collections allow duplicate elements and others do not. Some are ordered and others are unordered. Set. A collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets such as the cards comprising a poker hand, the courses making up a student's schedule or the processes running on a machine. List. An ordered collection sometimes called a sequence. Lists can contain duplicate elements. The user of list generally has precise control over where in the list each element is inserted and can access elements by their integer index position. Queue.
A collection used to hold multiple elements prior to processing. Besides the basic collections operation, a queue provides additional insertion, extraction, and inspection operations. Hues typically but do not necessarily order elements in a FIFO, first in, first out manner. Among the exceptions are priority queues, which order elements according to a supplied comparator or the elements natural ordering. Whatever the ordering used, the head of the queue is the element that would be removed by a call to remove or pull. In a FIFO queue, all new elements are inserted at the tail of the queue. Other queues may use different placement rules. Every queue implementation must specify its ordering properties.
Deque. A collection used to hold multiple elements prior to processing. Besides basic collection operations, a Deque provides additional insertion, extraction, and inspection operations. Deques can be used both as FIFO, first in, first out and LIFO, last in, first out. In a Deque, all new elements can be inserted, retrieved, and removed at both ends. Last, let's look at the benefits of the Java Collections Framework. The Java Collections Framework provides the following benefits; Reduces programming effort. By providing useful data structures and algorithms, the collection framework frees you to concentrate on the important parts of your program rather than on the low level plumbing required to make it work. By facilitating interoperability among unrelated APIs, the Java Collections Framework frees you from writing adapte objects or conversion code to connect APIs. Increases program speed and quality. This collection framework provides high performance, high quality implementations of useful data structures and algorithms.
The various implementations of each interface are interchangeable. So programs can be easily tuned by switching collection implementations because you're freed from the drudgery of writing your own data structures. You'll have more time to devote to improving programs, quality and performance. Allows interoperability among unrelated APIs. The collection interfaces are the vernacular by which APIs pass collections back and forth. If my network administration API furnishes a collection of node names and if your GUI toolkit expects a collection of column headings, our APIs will interoperate seamlessly even though they were written independently. Reduces effort to learn and to use new APIs. Many APIs naturally take collections on input and furnish them as output. In the past, each such API had a small sub-API devoted to manipulating its collections.
There was little consistency among these ad hoc collection sub-APIs. So, you had to learn each one from scratch and it was easy to make mistakes when using them. With the advent of standard collection interfaces, the problem went away. Reduces effort to design new APIs. This is the flip side of the previous advantage. Designers and implementers don't have to reinvent the wheel each time they create an API that relies on collections. Instead, they can use standard collection interfaces. Fosters software reuse. New data structures that conform to the standard collection interfaces are by nature reusable. The same goes for new algorithms that operate on objects that implement these interfaces. After this information about Java Collection Framework, let's take a short break here. In the next video, we'll talk about the collection interface. See you in the next video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.