I have added a sample program below that demonstrates the use of TreeMap with Selenium and Java. A TreeMap is a collection that stores key–value pairs and automatically sorts the keys in natural ascending order. Review the program, identify its output, and share your comments or observations below. Click the “Click for solution” button to view the explanation of the output.
package tests;
import java.util.TreeMap;
import org.testng.annotations.Test
public class SampleProgram12{
@Test
public void testMySkills() {
System.out.println("Output is"+fetchValue());
}
public int fetchValue() {
try {
TreeMap<Integer,Integer> map = new TreeMap<>();
map.put(3,5);
map.put(4,5);
map.put(2,3);
return map.firstEntry().getValue();
} catch (Exception ex) {
System.out.println(ex.getMessage());
return -1; // default/fallback value
}
}
}