How to find more than one web element in the list using Selenium?

At times, we may come across elements of the same type like multiple hyperlinks, images etc arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code and this can be done using WebElement List.


// Storing the element in  list
List <WebElement> elementList = driver.findElements(By.xpath(""));

// Get the size of the list
int listSize = elementList.size();

for (int i=0; i<listSize; i++)
    // iterate through element or perform any action