5 array list, data structure course
TRANSCRIPT
![Page 1: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/1.jpg)
using Java
2015
Data Structure Prepared by: Mahmoud Rafeek Al-farra
in Java
5. Array List
![Page 2: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/2.jpg)
mfarra.cst.ps www.fb.com/MahmoudRFarra
Contents
Example
The ArrayList Class
Introduction
Comparison between Arrays and ArrayList
![Page 3: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/3.jpg)
Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra
You can create an array to store objects. But, once the array is created, its size is fixed.
Nevertheless, you can still use arrays to implement dynamic data structures.
The trick is to create a larger new array to replace the current array, if the current array cannot hold new elements in the list.
![Page 4: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/4.jpg)
Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra
You can see an animated example from the following link:http://www.cs.armstrong.edu/liang/animation/web/ArrayList.html
![Page 5: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/5.jpg)
The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
Java provides the ArrayList class, which can be used to store an unlimited number of objects.
ArrayList is known as a generic class with a generic type E.
You can specify a concrete type to replace E when creating an ArrayList.
For example:ArrayList <String> cities = new ArrayList<> ();
![Page 6: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/6.jpg)
The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
![Page 7: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/7.jpg)
Example: The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
![Page 8: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/8.jpg)
Example: The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
![Page 9: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/9.jpg)
Comparison between Arrays and ArrayList
mfarra.cst.ps www.fb.com/MahmoudRFarra
![Page 10: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/10.jpg)
Array Listmfarra.cst.ps www.fb.com/MahmoudRFarra
The ArrayList is in the java.util package, it is imported in line 1.
Case Study: Develop a program that prompts the user to enter a sequence of numbers and displays the distinct numbers in the sequence. Assume that the input ends with 0 and 0 is not counted as a number in the sequence.
[ind, N.W]
![Page 11: 5 Array List, data structure course](https://reader035.vdocument.in/reader035/viewer/2022062412/587ad72d1a28ab542b8b46f9/html5/thumbnails/11.jpg)
using Java
2015
FB: M a h m o u d R F a r r aYouTube: M a h m o u d R F a r SlidesShare: mralfarra
Thank you