gpt4 book ai didi

java - 如何验证列表中的元素是否按字母顺序排序

转载 作者:行者123 更新时间:2023-11-30 03:13:47 24 4
gpt4 key购买 nike

I am using the following code to get the text values for employees from a web table and holding it in a list.Now i need to verify the employees stored in the list are in alphabetical order or not.

int count = a.getobjectcount(//*[@id='GridTable']/tbody/tr[*]);
List< String> list = new List<String>();
for(int i=0;i<=count-1;i++){
a.getTextFromElement("//*[@id='emp_" +i+ "']");

//Using for loop to get the number of employees and store it in a list

list.add(element)// i am adding employees to the list here
}

这里我需要验证员工是否按字母顺序排列或者不是 boolean==true;如果员工按字母顺序排列

最佳答案

调用此方法:

public static <E extends Comparable<E>> boolean isSorted(Iterable<E> coll) {
E prev = null;
for (E value : coll) {
if (prev != null && prev.compareTo(value) > 0)
return false;
prev = value;
}
return true;
}

关于java - 如何验证列表中的元素是否按字母顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33090617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com