WebDriver Tutorial : ArrayList Class In Java

In THIS POST, I accept described most one as well as 2 dimensional array In Java software development. Then query Is what Is arraylist In coffee as well as why nosotros bespeak It? Interviewer tin inquire you lot this query as well as hence you lot tin compass him response similar : arraylist Is a class that Implements listing Interface In coffee software evolution linguistic communication which supports dynamic array agency size of array tin grow equally needed. As you lot know, We tin practise solely fixed size array to shop values Inside It as well as that Is the limitation/drawback of array because when you lot don't know how many values you lot needs to shop In array as well as hence how tin you lot provide/define size of array? ArrayList helps us to overcome this limitation of array because It tin re-size automatically yesteryear Itself.

So lastly nosotros tin nation that when you lot don't know how many values you lot accept to shop In array, You tin operate ArrayList at house of elementary array inward coffee software program. We accept to operate arraylist many times In our selenium webdriver software automation  test instance development. Example : Store all links from page, shop all buttons Id from page etc.. In all such case, You volition non aware most how many values you lot accept to store.

Arraylist hierarchy inward java

VIEW NEXT POST to acquire most hashtable In Java software evolution linguistic communication for selenium webdriver

Bellow given representative volition demo you lot how to practise as well as piece of employment alongside arraylist shape In java. Same affair nosotros volition operate In selenium WebDriver assay out instance evolution to shop values.

//Import ArrayList shape header file import java.util.ArrayList;  populace shape ArrayList_Example {   populace static void main(String[] args) {   //Create object of ArrayList class. It volition shop solely string values.   ArrayList<String> Sample = novel ArrayList<String>();   //Now you lot tin shop whatever publish of values In this arraylist equally bellow. Size constrain volition comes never.   Sample.add("button1"); //Putting an Item In arraylist at Index = 0.   Sample.add("button2"); //Putting an Item In arraylist at Index = 1.   Sample.add("button3"); //Putting an Item In arraylist at Index = 2.   Sample.add("button4"); //Putting an Item In arraylist at Index = 3.      for(int i=0; i<Sample.size();i++){//loop volition execute till size of arraylist.    System.out.println(Sample.get(i)); //print arraylist values 1 yesteryear one.   }      System.out.println("*************************");   //To snuff it the Index of an Item from arraylist.   int ItemIndex = Sample.indexOf("button3");    System.out.println("Index Of button3 Item = "+ItemIndex);    System.out.println("*************************");        Sample.remove(1);//To take away an Item from arraylist.     for(int i=0; i<Sample.size();i++){    System.out.println(Sample.get(i));    }   System.out.println("*************************");      Sample.set(2, "Button8");//To reset value of an arraylist item.     for(int i=0; i<Sample.size();i++){    System.out.println(Sample.get(i));    }  } }

In inward a higher house example, I accept described how to created arraylist object, how to add together values In arraylist, How to snuff it Index of arraylist Item, How to take away arraylist Item, How to reset arraylist Item. You tin practise many to a greater extent than actions on arraylist object inward coffee software evolution language.

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post