gpt4 book ai didi

java - 带有哨兵值的分区列表

转载 作者:行者123 更新时间:2023-12-01 13:52:45 25 4
gpt4 key购买 nike

我有一个数组列表,其值例如

{ "november", "a","b","c","d", "december", "i","j","k", "april", "g","h" }

分割它的最佳方法是什么,这样我就可以根据月份拥有不同的数组。例如

List<String> novemberArray={"a","b","c","d"}

List<String> decemberArray={"i","j","k"}` 

等等..

我通过使用 Jsoup 解析 html 页面来获取此列表。

Elements tableRowElements = tableElements.select(":not(thead) tr");
for (int i = 0; i < tableRowElements.size(); i++) {
Element row = tableRowElements.get(i);
System.out.println("row : " );
Elements rowItems = row.select("tr");
for (int j = 1; j < rowItems.size(); j++) {
System.out.println(rowItems.get(j).text());
myList.add(rowItems.get(j).text());
}
}

myList 的值为 { "november", "a","b","c","d", "december", "i","j","k", "april ", "g","h"}列表是动态的,我对列表中的位置没有任何控制。使用子索引不会有帮助,因为它们经常变化。

最佳答案

一种方法是找到开始和结束索引并使用subList(int fromIndex, int toIndex)获取原始列表的一部分的 View 。

来自 API:

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

关于java - 带有哨兵值的分区列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19842586/

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