相关疑难解决方法(0)

从列表java中获取包含子列表的索引

我有字符串列表看起来像这样:

 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"} 
Run Code Online (Sandbox Code Playgroud)

我的期望是我想检查父列表是否包含序列子列表,然后在子列表的父列表中获取开始和结束索引.
从上面的例子:

 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] 
Run Code Online (Sandbox Code Playgroud)

我尝试使用List.containsAll方法,但它不关心列表项的顺序,我不能从这个方法获得开始和结束索引.
我正在寻找最快的方法,因为我的列表有很多数据,我必须从许多输入字符串中搜索.
任何帮助,将不胜感激!

更新:
我需要获取子列表的所有索引都包含在父列表中.例如,父级包含两个位置的child1:[2 - 3]和[6 - 7]

java list

5
推荐指数
1
解决办法
4640
查看次数

标签 统计

java ×1

list ×1