Selenium Java:将集合中的数字从低到高排序
我希望排序能从低到高进行,我该怎么做?您已经在调用Selenium Java:将集合中的数字从低到高排序,java,sorting,selenium,selenium-webdriver,Java,Sorting,Selenium,Selenium Webdriver,我希望排序能从低到高进行,我该怎么做?您已经在调用Collections.sort(numberList1)
Collections.sort(numberList1)然后,对列表进行排序
但是,您的numberList1
包含String
s。如果您使用泛型,您会立即在创建列表的地方看到它。它将是这样的List numberList1=new…
因此,排序将是字典式的,就像对文本进行排序一样。这就是为什么12
在3
之前,12
的第一个字符1
比3
小,依此类推
您只需将列表更改为整数列表:list
。然后你的分类将是你想要的。您可以使用Integer.parseInt(text)
或newinteger(text)
将String
s转换为Integer
s
干杯您需要将字符串转换为整数,并将其放入列表中以获得适当的排序。@KirillKogan如果用户回答了您的问题,请同时接受他的回答()。如果没有,请说明还有什么问题没有回答,这是StackOverflow的一个非常关键的部分,非常感谢。
driver.get("www.exmpale.com");
Thread.sleep(7000);
driver.findElement(By.cssSelector(".side-tab.side-generator")).click();
driver.manage().window().maximize();
Thread.sleep(30000);
// to find the 5 numbers in list1 and list 2 present in the header and
// add them in the list
for (int i = 0; i < 7; i++) {
numberList1
.add(
driver
.findElements(By.cssSelector(".generated-line"))
.get(0)
.findElements(
By.cssSelector(".generated-ball.animated.bounceIn>div")
)
.get(i).getText()
);
driver.switchTo().frame(driver.findElement(By.id("lotto-frame-games")));
// to find the numbers in the 2 boxes and add them in comparelist1 and
// comparelist2
for (int i = 0; i < 7; i++) {
compareList1
.add(driver
.findElements(
By.cssSelector(".select_num_col_part"))
.get(0)
.findElements(By.cssSelector(".main_active, .extra_active"))
.get(i).getText());
//to sort the lists so that lists can be compared easily.
Collections.sort(numberList1);
Collections.sort(compareList1);
System.out.println(numberList1.toString());
System.out.println(compareList1.toString());
[13, 16, 27, 34, 5, 7, 7]
[13, 16, 27, 34, 5, 7, 7]