Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Java:将集合中的数字从低到高排序_Java_Sorting_Selenium_Selenium Webdriver - Fatal编程技术网

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]