Using Collections Instead of Arrays

Using Collections Instead of Arrays
Overview
Difficulty
Beginner
Duration
2h 16m
Students
26
Description

In this course, we'll learn the Collection framework and the Map Interface.

Learning Objectives

  • Collection Framework vs Array
  • Hierarchy of Collection Framework
  • List interface - ArrayList Class
  • Iterator Interface
  • Set Interface
  • Queue and Dequeue Interfaces
  • Map Interface

Intended Audience

  • 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

Prerequisites

  • No prior knowledge is required about the Java programming language
  • Basic computer knowledge
Transcript

Hi there, in this section, we'll learn about the collections in Java. If you remember, we learned about arrays in our previous lessons. Thanks to array, we could store values of a similar type. For example, we could store multiple int values of type int in an array. So, do arrays meet all our needs or why do we need collections when we have array?

Let's take a look at the answers to these questions. We can examine this through the table on the slide. In the table, we can see the main differences between array and collections. First, let's look at the size. Arrays are fixed in size. That is, once we create an array, we cannot increase or decrease based on our requirement. Collections are growable in nature, that is, based on our requirements, we can increase or decrease of size. If you remember, the biggest disadvantage of arrays and indeed, the main reason we need collections is that arrays sizes are fixed. That is, while we were creating an array, we were specifying the size of the array and then, we could not add to this array. So, the size of the array was always fixed. 

Here, we use the collections framework in Java to eliminate this basic need. Another difference is the type of data they store. Arrays can hold both objects and primitive, but collection can hold only object types not primitive data types such as int, long, short etc. And if we compare in terms of the ready made method, there is no underlying data structure for arrays, hence ready-made method support is not available. But every collection class is implemented based on some standard data structure, and hence, for every requirement ready-made method support is available being a performance. 

We can use these methods directly and we are not responsible for implementing these methods. If we compare it in terms of memory usage, arrays are not recommended to use but collections are recommended to use. And last, if we compare it in terms of performance, arrays are recommended to use, but collections are not recommended to use. Yes, these are the main differences between arrays and collections. In this section, we will examine the collections in detail. Let's take a short break here. We'll go into collections in more detail in the next lesson. See you in the next lesson.

 

About the Author
Students
409
Courses
35
Learning Paths
2

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.

Covered Topics