WebDriver Java Tutorials : Hashtable

As we have learnt In my previous post, Using ArrayList in java software development Is very good alternative of array when you don't know how many values you have to store In array because ArrayList Is automatic dynamic growing array by Index. One more thing we needs to use In selenium webdriver software automation test case Is Hashtable in java. We will learn only basic thing about Hashtable to use It In our selenium WebDriver Test case development for software web application.

What Is Hashtable?
Hashtable Is a class In java software development language and provides us a structure to store key and its value as a pair In table format. Means we can store value with Its key and can access that value using Its key. There Is not any Index of value In Hashtable. Key's Hashcode will be used to map the value with key In Heshtable. Let me show you very simple example of Hashtable In java software development language.

//Import Hashtable header file.
import java.util.Hashtable;

public class Hash {
 public static void main(String[] args) {
  //Created hashtable class object to use Its different properties.
  Hashtable<String, Integer> t1 = new Hashtable<String, Integer>();
  t1.put("Legs", 4); //Store value 4 In key = Legs
  t1.put("Eyes",2); //Store value 2 In key = Eyes
  t1.put("Mouth",1); //Store value 1 In key = Mouth
  
  //Accessing hash table values using keys.
  System.out.println("Animal Legs = " +t1.get("Legs"));
  System.out.println("Animal Eyes = " +t1.get("Eyes"));
  System.out.println("Animal Mouth = " +t1.get("Mouth"));
 }
}

Need More Tutorials On Java And Selenium WebDriver? VISIT THIS PAGE

As you see In above example, I have created object of Java Hashtable class and then store values with Its unique keys. Then I have used keys to access and print Its values. This way we can store and access values from hash table whenever required In java software development language.

6 comments: