5 array list, data structure course
TRANSCRIPT
using Java
2015
Data Structure Prepared by: Mahmoud Rafeek Al-farra
in Java
5. Array List
mfarra.cst.ps www.fb.com/MahmoudRFarra
Contents
Example
The ArrayList Class
Introduction
Comparison between Arrays and ArrayList
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.
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
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<> ();
The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
Example: The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
Example: The ArrayList Classmfarra.cst.ps www.fb.com/MahmoudRFarra
Comparison between Arrays and ArrayList
mfarra.cst.ps www.fb.com/MahmoudRFarra
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]
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