我已经使用ArrayList和HashSet编写了以下代码。但是哈希集无法按预期工作,这意味着它不会删除重复的项目。但哈希集不允许重复。
**HTML** code
<HTML>
<BODY>
<select id= 'WesInn'>
<option value = 'idli'> IDLI</option>
<option value = 'vada'> VADA</option>
<option value = 'sambhar'> SAMBHAR</option>
<option value = 'Manchurian'> MACHURIAN</option>
<option value = 'idli'> IDLI</option>
<option value = 'sambhar'> SAMBHAR</option>
<option value = 'Tea'> TEA</option>
</select>
</body>
</html>
public class Assgn_DropDownAsc {
//static String text;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("C:\\Users\\admin\\Desktop\\New folder/Dropdown.html");
List list = new ArrayList ();
LinkedHashSet hs = new LinkedHashSet();
Adding ArrayList elements to the HashSet
//in order to remove the duplicate elements and
//to preserve the insertion order.
hs.addAll(list);
//System.out.println(hs);
//Removing ArrayList elements
hs.clear();
System.out.println(hs);
System.out.println(list);
//Adding LinkedHashSet elements to the ArrayList
hs.addAll(list);
//System.out.println(alloptions.size());
System.out.println(list);
}
}
输出:
[IDLI VADA SAMBHAR MACHURIAN IDLI SAMBHAR TEA]
开心每一天1111
相关分类