我有像这样的字符串列表:
List<String> parentDataList: {"this", "is", "a", "test", "string", "and", "a", "test", "other"}
List<String> child1: {"a", "test"}
List<String> child2: {"this", "string"}
List<String> child3: {"is", "a", "test"}
我的期望是检查父列表是否包含序列子列表,然后根据子列表在父列表中获取起始和结束索引。
从上面的例子可以看出:
Parent contain child1 list, and return the indexes: [2 - 3] and [6 - 7]
Parent doesn't contain child2 list because it isn't sequential.
Parent contain child3 list, and return the index: [1 - 3]
我尝试使用
List.containsAll
方法,但它不关心列表项的顺序,并且我无法从该方法中获取起始和结束索引。因为我的列表有很多数据,并且我必须从许多输入字符串中搜索,所以我正在寻找最快的方法。
感谢任何帮助!
更新:
我需要获取包含在父列表中的所有子列表的索引。例如,父列表在两个位置都包含child1:[2-3]和[6-7]
indexOfSubList
。 - Holger