ArrayList

Keep in mind
  • Java ArrayList class can contain duplicate elements.
  • Java ArrayList class maintains insertion order.
  • Java ArrayList class is non synchronized.
  • Java ArrayList allows random access because array works at the index basis.
  • In Java ArrayList class, manipulation is slow because a lot of shifting needs to be occurred if any element is removed from the array list.
Example 1 : Iterating through while loop
package com.tutorial.one;

import java.util.*;
public class CollectionArrayList {
 public static void main(String args[]){
 ArrayList<String> list = new ArrayList<String>();
 list.add("Tarun");
 list.add("Nakul");
 list.add("Prathith");
 list.add("Parth");
 
 Iterator itr = list.iterator();
 while(itr.hasNext()){
 System.out.println(itr.next());
 }
 }
}
Example 2 : Iterating through for-each loop
package collection;

import java.util.*;
public class ArrayListExample {
 public static void main(String args[]){
 ArrayList<String> list = new ArrayList<String>();
 list.add("Tarun");
 list.add("Valera");
 list.add("Khatri");
 for(String obj:list)
 System.out.println(obj);
 }
}

 

 

Selenium 3.0

Selenium 3.0 with firefox

package com.tutorial.one;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.firefox.FirefoxDriver;
 import org.testng.annotations.*;

public class Firefox {
 private WebDriver driver;
 private String baseUrl;

@BeforeClass
 public void setUp() throws Exception {
 System.out.println("setting GeckoDriver");
 System.setProperty("webdriver.gecko.driver", "C:\\Users\\tarun\\geckodriver.exe");
 driver = new FirefoxDriver();
 baseUrl = "http://tfortesting.com";
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }

@Test
 public void openSite() throws Exception{
 System.out.println("opening tfortesting.com");
 driver.get(baseUrl);
 driver.manage().window().maximize();
 driver.findElement(By.linkText("Java")).click();
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }

@AfterClass
 public void endTest() throws Exception{
 driver.quit();
 }
 }

Selenium 3.0 with Chrome

package com.tutorial.one;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.*;

public class Chrome {
 private WebDriver driver;
 private String baseUrl;
 
 @BeforeClass
 public void setUp() throws Exception {
 System.out.println("setting Chrome driver");
 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
 driver = new ChromeDriver();
 baseUrl = "http://tfortesting.com";
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }
 
 @Test
 public void openSite() throws Exception{
 System.out.println("opening tfortesting.com in chrome browser");
 driver.get(baseUrl);
 driver.manage().window().maximize();
 driver.findElement(By.linkText("Java")).click();
 Thread.sleep(5000);
 }
 
 @AfterClass
 public void endTest() throws Exception{
 driver.quit();
 }
}

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑