Use of Collection and Selenium Webdriver

Collections in java is a framework that provides an architecture to store and manipulate the 
group of objects. The Collection helps the user to store only the Object class type, but every 
single class in java is subclass to Object class, which means we can store anything with help 
classes present in the collection.
  
  
Where we use collections in selenium : Whenever we deal with more than one item, then we 
use collections in selenium webdriver. Few places are:
  

when we try to retrieve the more than one match of elements
when we handle multiple tabs/windows
When we retrieve option from the dropdown using getOptions() method
  
  
how to use arraylist in selenium webdriver
As per my knowledge, we do not use ArrayList in selenium, but we do use List. People prefer List 
over ArrayList because when you use a List, you can store a different kind of list categories 
like ArrayList, LinkedList, TreeList so on. But when we use ArrayList, then we can only store 
only the ArrayList type.

This is the primary reason why the findElements method returns List(broad) rather than ArrayList(narrow).
  
  
Now if you are like me then you get this doubt, why cannot I use ArrayList for it instead of List.
So we have to store the value based on the return type only, so when you should store the list of web elements using List only. But I did not mean that we cannot store the list of web elements in ArrayList, but it is not recommended. If you think who cares about the recommendation, then you got to downcast the returned values to store it in ArrayList with selenium.
For example, if we want to verify a value by splitting the string output, then splitting always returns an Array of values., there values will be substrings.
Few things to remember about for each loop: It starts with the keyword for like a normal for-loop. Instead of declaring and initializing a loop counter variable, you declare a variable that is the same type as the base type of the array, followed by a colon, which is then followed by the array name. In the loop body, you can use the loop variable you created rather than using an indexed array element. It's commonly used to iterate over an array or a Collections class (e.g., ArrayList, HashSet) You might need to declare a variable outside the loop if you want to terminate the loop after some iterations how to use Set in selenium webdriver Java Set is a collection of objects that allows no duplicate elements to be stored. Java Set is an interface that extends the Collection interface. Unlike List, Java Set is NOT an ordered collection; its elements does NOT have a particular order. Java Set does NOT provide control over the position where you can insert an element. You cannot access elements by their index and also search elements in the list. Set is used when we are dealing with a unique element or values like window handles, getWindowHandles()returns set of String Set allGUID = driver.getWindowHandles(); how to use the Map in selenium We can use Maps or hashMaps in selenium when we want to read key-pair values; For example, when we read data from the properties files or JSON file, we would be using HashMaps along with Selenium. Maps are perfect to use for key-value association mapping such as dictionaries. The maps are used to perform lookups by keys or when someone wants to retrieve and update elements by keys. Some examples are: A map of error codes and their descriptions. A map of zip codes and cities. A map of managers and employees. Each manager (key) is associated with a list of employees (value) he manages. A map of classes and students. Each class (key) is associated with a list of students (value).