A Quick Overview Of Collections In Programming

COLLECTION

Collection is a specialized array which is meant to help the developers by reducing their time of writing the array code. I have explained six classes of Collection below.

  1. ArrayList
  2. Queue
  3. Stack
  4. Hashtable
  5. Sorted List
  6. BitArray

ArrayList

ArrayList is the most basic, simple, and un-ordered collection. ArrayList is used to add and remove items in a very simple and straight forward way. The following points will make this topic easier to understand.

  1. ArrayList is the most basic class of all classes.

  2. You can also use indexer to set a specific object in a Collection.

  3. ArrayLists are dynamic collections. They support “Add Method”, “AddRange Method”. Also, the ArrayList also supports inserting an object in a specific location; “Insert method” is used to accomplish this task.

  4. Add method allows you to add a single item of any type in a collection.

  5. AddRange method is used to add a range of an item, usually added from another collection or an array.

  6. Insert method  is used to add items on specific location.

  7. Remove method is used to remove a single item from the collection.

  8. ArrayList supports three methods for removing the items, “Remove method”, “RemoveAt method” and “RemoveRange method”.

  9. RemoveAt method allows you to remove an item in a particular index. Whereas RemoveRange method is used to remove a range of the indexes, at once, present in collection.

The following pictorial view will help you understand the ArrayList in an easier way. 

understand array

Examples

understand array

understand array

understand array

understand array

understand array

understand array

understand array

understand array

understand array

understand array

understand array

understand array

Queue

Queue is a "First-In, First-Out" collection. Queue class is meant to create a list of objects. It can add, remove, and retrieve items by using enqueue, dequeue, and peek methods, respectively. The following points will help you understand the queue in a better way.
  1. Queue treats objects like bank treats its customers in line.

  2. Queue stores the data on sequential basis. That’s why it is called sequential collection also.

  3. Queue allows duplicate items.

  4. Queue allows null values.

  5. Queue’s most famous three methods are “peek”, “dequeue”, and “enqueue”.

  6. Enqueue method is used to add item in collection.

  7. Dequeue method retrieves an item from the front of the queue and removes it at the same time.

  8. Peek method is used to retrieve data from the list.

This diagram will help you understand the queue class in an easier way.understand array
Examples

Stack

Stack is a "Last-In, First-Out" collection. Its best examples include guns, plats, and playing cards etc. After making instance, you can use the methods of stack. Following are the behaviors of stack which help you understand the stack.

  1. Stack allows duplicate values.

  2. Stack allows null values.

  3. Stack is also a sequential collection, just like queue.

  4. Stack supports three famous method which are known as POP, PUSH and PEEK.

  5. POP is used to remove the item from the stack after retrieving it from the top of the stack.

  6. PUSH is used to add items in the stack.

  7. PEEK is used to retrieve items from the stack.

The following image will help you understand the stack class in an easier way.

Examples

understand queue

understand queue

Hash table

Hashtables are the combination of rows and columns, with some keys and values. The following points will help you understand the hashtable more easily.

  1. It uses integer value which is called hash.

  2. Hash is used to speed up the searching for the specific key in collection.

  3. Keys are case sensitive and cannot be null in hash table.

  4. If you try to store the same key twice, then it will replace the first call by second call.

  5. Values can be duplicated in hash tables.

  6. It has no fixed data types.

  7. It uses namespaces like system.Collection.

The following diagrammatic view will help you understand the hashtable in an easier way.
nderstand hash table
Examples

nderstand hash table

nderstand hash table

Sorted List

It is clear from its name that this class of collection is used for sorted data. It slightly works like hash table. Some of its properties are given below.

  1. It always gives sorted result.

  2. It uses key and value pair like hashtable.

  3. You can also add values directly without assigning key in sorted list.

  4. It uses RemoveAt method to delete specific value.
It uses Contain Keys to determine whether the collection contains the specific key or not.nderstand hash table
Examples





Bit Array

Bit array is a specialized array meant to deal with Boolean expressions. Bit array is a class level thing which needs instance. Following points will help you understand the bit array easily.

  1. Bit array deals with the Boolean expression.

  2. By default, the value of Boolean expression in bit array is false.

  3. You can set the value of Boolean expression by using indexer.

  4. Bit array also support common operation such as AND, NOT, OR & Xor operation.

  5. Bit array class is a resizable class that can store Boolean expression.

  6. We define the size of bit array at the same time when we create its instance.

  7. Bit array does not support ADD & REMOVE methods just because each value in bit array can only be true or false.

Here is the diagrammatic view of bit array which will help you understand the bit array class more easily.

nderstand bit table

Ebook Download
View all
Learn
View all