
What are the Classes under the Set Interface?.What are the Classes under the List Interface?.What is the difference between Collections and Arrays classes?.How many types of classes/interfaces are there in Collection Framework?.How does a Map differ from a Collection?.How is the Collection better than Array in Java?.You can have the provider pushing events in a queue and one or more consumers asynchronously polling from the queue. Where the processors process the events asynchronously. The best suited example is an event driven architecture. You can use queues for storing the elements before processing. Hence the PriorityQueue difference from the concept of FIFO. With these queues you can pass your own comparator or let the queue return objects in their natural order. Java Queue implementations and implementations of its child interfaces provide convenience methods. However, in Java the Queue implementations differ from the concept of FIFO for good. Also, considering it’s tube like structure the element which was inserted first will be first to come out. In other words, with queues you can insert an element from one end and remove from the other. In general, Queues are First In First Out (FIFO). Queue is a type of Data Structure, that resembles a tube with two ends. Otherwise, it populates and returns a new array of the same type. Moreover, It returns the same array if the collection elements fit into the given array. T toArray(T a): Converts the collections to an array of type of given array.Object toArray(): Converts the collection to an array.int size(): Returns the size of the collection.boolean retainAll(Collection c): Removes everything except the elements of given collection.boolean removeAll(Collection c): Removes all the elements.boolean remove(Object o): Removes an element which is equals to the given element.Which is used to iterate through the collection. Iterator iterator(): Returns an instance of Iterator.boolean containsAll(Collection o): Returns true if the given elements of the given collection are present.boolean contains(Object o): Returns true if given element is present in the collection.void clear(): Removes all the elements from the collection.boolean addAll(Collection e): Adds all the elements in given collections to the collection.boolean add(E e): Adds given element to the collection.Before we go further, let’s have a look at some to the basic methods from Collection interface. These methods includes methods to add, remove, modify, check and read elements from a collection. This interface defines some of the basic methods to work with collections. In other words, all the other collections interfaces and implementation inherit this super interface.

Java has provided Collection interface, which is the super interface of the hierarchy. The Java programming language provides many different types of Collections. Some do support sorting or maintain order of insertion, while other do not. For example, some of the collections have indexes and some of them store elements in key value pattern. Hence, you get a choice to use a very specific type of collection that is based on your data and requirement. However, Java Collections Frameworks, based on different requirements provide different types of collections. You use the index to add, modify or remove respective element from an array.Īrrays are the base of Java Collections Framework. While, each memory location is identified with a sequential index. Also, they have fixed size and fixed memory locations. Arrays are nothing but collection of related or unrelated data. Certainly, almost all general programming languages including Java support arrays.

The objects your store in a collection are called as elements.īefore we go further, it is important to understand what is an Array. But, in that case those objects belong to a common type of Object. Although you may store different types of objects in a collection. Collections stores objects of similar types. You can use collections to store datasets in the form of objects.

