Tuesday, June 20, 2017

Part-2 COLLECTIONS :ARRAY LIST

So in the above example , we have created an array list object arrobj .
To add elements in the arrobj , we have called the add method on arrobj.
After printing the arrobj, we get the desired result i.e values are added in the arrobj.


But the question is how add(object) method adds the value in ArrayList ?

Answer :
There are 2 overloaded methods add (methods in array list):

1. add(object) : adds object to the end of the List.
2. add(int index, object) : inserts the specified object to the specified position in the list

ArrayList internally uses array object to add or store the elements .In other words Array List is backed by Array data-structure. The array of Array List is re sizable or dynamic.

There are 2 ways to create an ArrayList object :-
a. Create an empty list with initial capacity:
List arrlistobj= new ArrayList();
When you create an ArrayList this way , the default constructor of the ArrayList class is invoked .
It will create internally an array of object with default size to 10.

b. List arrlistobj = new ArrayList(20);
When we create an arrayList this way , the array list will invoke the constructor with the integer argument . It will create internally an array of object . The size of the object[] will be equal to the argument passed in the constructor . Thus when above line of code is execute it creates an object[] of capacity as 20.
Thus ArrayList constructor will create an empty list . Their initial capacity can be 10 or equal to the value of the argument passed in the constructor.

List arrlistobj= new ArraList(Collection c);
The above ArrayList constructor will create a non empty list containing elements of the collection passed in the constructor.























5 comments:

cathyouellette said...

i am glad to discover this page : i have to thank you for the time i spent on this especially great reading !! i really liked each part and also bookmarked you for new information on your site.Top QA Companies
Top Automation Testing Companies
Top Mobile App Testing Companies
Top Performance Testing Companies

Unknown said...

This is really a worthy and wonderful blog to read and further more tips on the QA Services have been learnt. Nice Post.. really helpful to clear my small concepts. thanks :)Keep doing more, waiting to read your next blog security testing services. Visit here for more information about Vulnerability assessment services and penetration testing services.

devibala said...

when I end up, I realised this content worth a lot
selenium webdriver with java
java with selenium jobs

Lavanya said...

An awesome blog for the freshers. Thanks for posting this information.
Selenium Testing Course Online
Best Selenium Course Online

Lavanya said...

your valuable information and time. Please keep updating.
Best Selenium Course Online
Selenium with Java Online Training

About Me

My photo
Pune, Maharastra, India
You can reach me out at : jimmiamrit@gmail.com