I have given program below with the usage of TreeSet using Selenium and Java. We can use TreeSet to sort the values in sequential order. You can review the execution output generated by the Selenium script and share your comments. Click the “Click for solution” button to view the explanation of the output.
package tests;
import java.util.List;
import java.util.TreeSet;
import java.util.ArrayList;
import org.testng.annotations.Test
public class SampleProgram11{
@Test
public void testMySkills() {
System.out.println("Output is"+fetchValue());
}
public int fetchValue() {
try {
List<Integer> list = new ArrayList<>();
list.add(4);
list.add(3);
list.add(7);
TreeSet<Integer> treeSet = new TreeSet<>();
for (int val : list) {
treeSet.add(val);
}
return treeSet.first(); // smallest element
} catch (Exception ex) {
System.out.println(ex.getMessage());
return -1; // default/fallback value
}
}
}