Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
Key Takeaways
Explains Java ArrayList and its various constructors and methods
Full Transcript
hello everyone this is Neha from edureka and I welcome you all to this session on Java arraylist as you all are aware in Java arrays are an important data structure to store data but array static in size and is suitable for fixed length data structure so what if you wish to have a variable and data structure so that you can store the elements in an array dynamically in this video I will introduce you the important class of collections framework or arraylist which allows you to store the elements dynamically as it is resizable let's look at the topics to be covered in this session first and foremost I will talk about hierarchy of arraylist class and collections framework next I will tell you what is arraylist and its internal working once you understand the basics then I will take you to the programming part wherein I will be explaining various Constructors and methods supported by arraylist along with examples and finally I will wrap up the session by explaining benefits of arraylist over arrays without any further Ado let's get started a Java collection and framework provides an architecture to store and manipulate a group of objects and it includes interfaces classes and algorithm in this figure blue boxes refers to the different interfaces and the gray color rectangles defines the class so here list is an interface and arraylist linked list Vector all these classes implements list as an interface similarly as DQ is also a interface so it extends an inherit skew interface now talking about arraylist it uses a dynamic array for storing the elements it inherits abstract list class and implements list interface then list interface extends collection and iterable interfaces in hierarchical order so this is about the hierarchy of arraylist class now let's see what is arraylist arraylist is a part of collection framework and is the implementation of list interface where the elements can be dynamically added or removed from the list also the size of the list is increased dynamically if the elements are added more than initial size though it may be slower than the standard arrays but can be very helpful in programs where lots of manipulation in the array is required some key points to note here arraylist is initialized by a size however the size can increase if the collection grows or shrunk if the objects are removed from the collection next arraylist allows us to randomly access the list and arraylist cannot be used for primitive types like end care Etc to access all those we need a Wrap or class for such cases now let's move further and say the internal working of arraylist first we create a empty array and then go on adding the elements once the size of the array is full that is if the size of the current elements is greater than the maximum size of the array then we have to increase the size of the array but the size of the array cannot be increased dynamically so what happens internally is a new array is created and the old array is copied to the new array so by this automatically the size will be doubled and it will be increased so you can go on adding the elements how much you require so that's how it works internally now let's see the various construct supported by Java arraylist first arraylist this Constructor Builds an empty arraylist coming to syntax my array is a reference to an array list that holds the references to object of Type e array has an initial capacity of 10 cells although the capacity will be increased as needed as references are added to the list and cells will contain references to objects of Type e next array list of collection C this Constructor is used to add all the elements of specified collection C to the current arraylist that is you can add all the specified collection C to the current arraylist next array list of incapacity here this is used to build an arraylist that has a specified initial capacity and initial capacity is the number of cells that the arraylist starts with it can expand Beyond this capacity if you add more elements now let's see a small example to understand how and where these Constructors are used in arraylist I will open my eclipse and first create package called edureka now I will create a class called Constructor the very first thing that I do before writing the code is I will import util.star package now let's begin with the code I will first create a arraylist of type string I initialize the counter value to 0 and using Advanced for loop I am trying to increase the count of counter but we don't have any elements present in the arraylist so if I try to print the counter value it will not retain any value why because we don't have any elements present in the list okay now I will create one more arraylist and initialize the capacity to that I'll change the name and give it as B and I will initialize the capacity to 30 okay now again if you try to print the count of value it will not print because we have just initialized the capacity again if we try to obtain the value of counter it won't get incremented why because we don't have anything in the list now let's create a string array and add some elements into it after creating a string array I will create a object of arraylist and then append a element using add method so let's see how to do that so this is how I will add element using add method now I will use Advanced for Loop to print the elements present in the arraylist now let's run the program and see what will be the output so here is the output as I have already told it won't return the counter value because the arraylist is empty and the counter value will be automatically zero next on creating a string and adding the elements it has retrieved all the elements present in the string even with the one that we have added that is j2w so this is how Constructors are used in arraylist now let's dive into the various methods supported by arraylist first add method this method is used to add the elements to the arraylist that is it is used to insert a specific element at a specific position index in a list for example you can create RL list and go on adding the elements using the add method we will demonstrate and see all the methods of arraylist in Eclipse after knowing the concepts of them next clear method this method is used to remove all the elements from the list that is you can just use Clear method to remove all the elements present in the list next trim to size this method trims the capacity of an arraylist instance to the Ellis current size that is if you are creating an array list of size 9 and if you are adding only three elements to that on calling this method trim to size it trims the size of arraylist from 9 to 3 that is it reduces the arraylist size to the number of element that it contains in the arraylist next index of this method Returns the index of first occurrence of the specified element in the list if that element is not present in the list then it returns -1 suppose in this case if you want to return the index of 5 and if you write here 5 then it will return a of 2 because a of 1 and a of 2 but if you try to find the index of 3 which is not present in the array list then it will return -1 that is it returns -1 if the list does not contain the particular element next object clone this method is used to return a copy of the arraylist that is on calling this method it clones the entire arraylist so for example if you are adding two elements in the array and you're cloning the entire thing then again after clone list it will return the whole element present in the arraylist next object to array this method is used to return an array containing of all the elements in the list in the current order for example if you have all the elements in the list then it will return all the elements in the list in the correct order next remove method this method removes the first occurrence of a specified element from the list if it is present for example if you want to remove n from the added list then it removes the first occurrence of n if there is one more occurrence of n here it won't remove that next in size this Returns the number of elements in the list that is the size of the list suppose say we have added four elements then it Returns the size of the arraylist as 4. now let's demonstrate all the methods and see how it works and how it is used I'll create one more class called arraylist now in this example we'll see how to add the elements we'll create array list of type Al that is a reference and we'll go on adding the elements into this now we have added three elements now let's try to print the size of the array and the contents present in the array let's execute and see what will be the output so the size of the arraylist is 3 and the contents of array is a Eureka Java and arrays now I want to remove Java from the list so what will I do here is I will use a remove method to remove the element from the list now again let's print the size of the arraylist after deletions so when you remove Java from the list it retrieved only a Eureka and arrays and the size will be decreased to 2. so this is how we can remove the element we can add the elements and we can retrieve the size of the arraylist now let's see how to clone the arraylist first we'll make cloneless as object and then call the method now let's execute and see how the Clone list appears so as we have already removed the elements from the list so it returns only the elements after deletion in the Clone list so if I make whole remove part as comment and execute then it will retrieve the entire elements present in the arraylist see that is elements in the cloneless star edureka Javin arrays now let's see how object to array method works on executing this this is how the output looks now let's use Clear method and clear the arraylist it's very simple al.clear and print the elements after applying clear method nothing will be present in the array that is the entire list will be cleared now let's see how to create a custom arraylist and add the elements remove the elements and retrieve the size of that I'll create a class called custom array say I want to create a class of student data wherein I will be initializing role number name marks and phone number so let's see how to do that I'll create a class called student datum and initialize the variables now I will create a Constructor and add the reference to these variables now let's begin with the main method now let's create a custom arraylist and reference the variables using add values method I'm adding the values now I will invoke this function and Define it here I'm invoking list dot add method to add the elements in the list now in order to print the values present in the list I am invoking a function called print values of list and here I will give the definition for that and now let's print the values present in the list now let's execute and see what will be the output that is at this place all the elements present in the array list that is the roll number name marks and mobile number now if you want to remove one of the rows from the arraylist let's see how to do it using remove method here I will give list dot remove now if you want to remove the row of elements from the arraylist then you can remove the elements from the list and then print the rest of the elements so let's see what will be the output so output is like this first it has printed all the elements present in the list then it printed the size of the list and it removed the first occurrence when you use remove method it removes the first occurrence present in the list that is it removes the first value so it has removed the first row that is Chris and it retrieved the rest of the elements so that's how you can create a custom error list and add the elements accordingly now let's jump into the last topic of today's discussion that is advantages of arraylist over array first arraylist is variable length arrays are of fixed length you cannot change the size of the array once they are created but arraylist is variable and that is it can grow and Shrink dynamically next size of the array can be modified dynamically when you add the elements into an array the size will be increased and if you remove the elements the size will be automatically decreased next you can add any type of the data may be list Union structure Etc not only that it also allows you to add the duplicate elements in the list next you can Traverse an arraylist in both the directions that is forward and backward directions using list iterator and it also allows you to insert and remove the elements at a particular position so I hope you understood the concept of arraylist and the difference between array and arraylist that's all for the session thank you and have a nice day
Original Description
🔥𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐉𝐚𝐯𝐚 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠: https://www.edureka.co/java-j2ee-training-course (Use code "𝐘𝐎𝐔𝐓𝐔𝐁𝐄𝟐𝟎")
This Edureka tutorial video on “Java ArrayList” (Java blog series: https://goo.gl/osrGrS) will give you a brief insight about ArrayList in Java and its various constructors and methods along with an example. Through this video, you will learn the following topics:
00:00:00 Introduction
00:01:10 - Collections Framework
00:01:42 - Hierarchy of ArrayList
00:01:56 - What is ArrayList
00:02:41 - Internal Working of ArrayList
00:03:18 - Constructors of ArrayList
00:04:22 - Constructors Example
00:07:13 - ArrayList Methods
00:09:49 - Methods Example and Demo
00:16:08 - Advantages of ArrayList over Arrays
🔴 Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV
📝Feel free to share your comments below.📝
🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐎𝐧𝐥𝐢𝐧𝐞 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐚𝐧𝐝 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬
🔵 DevOps Online Training: http://bit.ly/3VkBRUT
🌕 AWS Online Training: http://bit.ly/3ADYwDY
🔵 React Online Training: http://bit.ly/3Vc4yDw
🌕 Tableau Online Training: http://bit.ly/3guTe6J
🔵 Power BI Online Training: http://bit.ly/3VntjMY
🌕 Selenium Online Training: http://bit.ly/3EVDtis
🔵 PMP Online Training: http://bit.ly/3XugO44
🌕 Salesforce Online Training: http://bit.ly/3OsAXDH
🔵 Cybersecurity Online Training: http://bit.ly/3tXgw8t
🌕 Java Online Training: http://bit.ly/3tRxghg
🔵 Big Data Online Training: http://bit.ly/3EvUqP5
🌕 RPA Online Training: http://bit.ly/3GFHKYB
🔵 Python Online Training: http://bit.ly/3Oubt8M
🌕 Azure Online Training: http://bit.ly/3i4P85F
🔵 GCP Online Training: http://bit.ly/3VkCzS3
🌕 Microservices Online Training: http://bit.ly/3gxYqqv
🔵 Data Science Online Training: http://bit.ly/3V3nLrc
🌕 CEHv12 Online Training: http://bit.ly/3Vhq8Hj
🔵 Angular Online Training: http://bit.ly/3EYcCTe
🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐑𝐨𝐥𝐞-𝐁𝐚𝐬𝐞𝐝 𝐂𝐨𝐮𝐫𝐬𝐞𝐬
🔵
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from edureka! · edureka! · 60 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
▶
ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
edureka!
Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
edureka!
Java script interview question and answers | Java script training | Edureka Rewind
edureka!
OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
edureka!
What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
edureka!
Top 10 Applications of Machine Learning in 2023 | Machine Learning Training | Edureka Rewind - 7
edureka!
Machine Learning Engineer Career Path in 2023 | Machine Learning Tutorial | Edureka Rewind - 6
edureka!
10 Must Have Machine Learning Engineer Skills That Will Get You Hired | Edureka Rewind - 7
edureka!
Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
edureka!
Python Lists | List in Python | Python Training | Edureka Rewind
edureka!
Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
edureka!
Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
edureka!
How to use Pandas in Python | Python Pandas Tutorial | Python Tutorial | Edureka Rewind
edureka!
Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial | Edureka Rewind
edureka!
Top 10 Reasons to Learn Tableau in 2023 | Tableau Certification | Tableau | Edureka Rewind
edureka!
Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
edureka!
Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka Rewind
edureka!
Realtime Object Detection | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
edureka!
Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training | Edureka Rewind
edureka!
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
edureka!
Phases in Cybersecurity | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
edureka!
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
edureka!
Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
edureka!
React vs Angular 4 | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
edureka!
ReactJS Components Life-Cycle Tutorial | React Tutorial for Beginners | Edureka Rewind
edureka!
Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
edureka!
Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
edureka!
Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
edureka!
The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
edureka!
What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
edureka!
Google Cloud IAM | Identity & Access Management on GCP | Edureka | GCP Rewind - 5
edureka!
Google Cloud AI Platform Tutorial | Google Cloud AI Platform | GCP Training | Edureka Rewind
edureka!
Projects in Google Cloud Platform | GCP Project Structure | GCP Training | Edureka Rewind
edureka!
How to Become a Data Scientist | Data Scientist Skills | Data Science Training | Edureka Rewind - 3
edureka!
Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
edureka!
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
edureka!
What is Honeycode? | Introduction to Honeycode | Edureka
edureka!
Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
edureka!
DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
edureka!
Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
edureka!
How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
edureka!
Python Developer | How to become Python Developer | Python Tutorial | Edureka Rewind
edureka!
How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer | Edureka
edureka!
Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
edureka!
Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program | Edureka Rewind
edureka!
DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
edureka!
How to Become a DevOps Engineer? | DevOps Engineer Roadmap | Edureka | DevOps Rewind
edureka!
How to Become a Data Engineer? | Data Engineering Training | Edureka
edureka!
How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
edureka!
Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
edureka!
Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training | Edureka Rewind
edureka!
Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
edureka!
Big Data Hadoop Tutorial For Beginners | Hadoop Training | Big Data Tutorial | Edureka Rewind
edureka!
Big Data Analytics | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
edureka!
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | Edureka Rewind
edureka!
Triggers in Salesforce | Salesforce Apex Triggers | Salesforce Tutorial | Edureka Rewind
edureka!
How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training Edureka Rewind
edureka!
Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
edureka!
Related AI Lessons
⚡
⚡
⚡
⚡
Docker Explained: From “What Even Is This” to Deploying a Full-Stack App
Medium · DevOps
I Used to Pay for Cloud Servers. Then I Found a Way to Run One Free, 24/7
Medium · AI
KEDA 2026: Event-Driven Autoscaling Patterns That Shrank Our AWS Bill by 40%
Medium · DevOps
AWS CloudFormation and CDK Explained: Infrastructure as Code on AWS
Medium · DevOps
Chapters (10)
Introduction
1:10
Collections Framework
1:42
Hierarchy of ArrayList
1:56
What is ArrayList
2:41
Internal Working of ArrayList
3:18
Constructors of ArrayList
4:22
Constructors Example
7:13
ArrayList Methods
9:49
Methods Example and Demo
16:08
Advantages of ArrayList over Arrays
🎓
Tutor Explanation
DeepCamp AI