java.util.Collections.indexOfSubList()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中java.util.Collections.indexOfSubList()方法的一些代码示例,展示了Collections.indexOfSubList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.indexOfSubList()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:indexOfSubList

Collections.indexOfSubList介绍

[英]Searches the list for sublist and returns the beginning index of the first occurrence.

-1 is returned if the sublist does not exist in list.
[中]在列表中搜索子列表并返回第一次出现的开始索引。
-如果列表中不存在子列表,则返回1。

代码示例

代码示例来源:origin: apache/kafka

private boolean in(List<String> cycle, Set<List<String>> cycles) {
  List<String> superCycle = new ArrayList<>(cycle);
  superCycle.remove(superCycle.size() - 1);
  superCycle.addAll(cycle);
  for (List<String> foundCycle: cycles) {
    if (foundCycle.size() == cycle.size() && Collections.indexOfSubList(superCycle, foundCycle) != -1)
      return true;
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

public static int findArray(Integer[] array, Integer[] subArray)
{
  return Collections.indexOfSubList(Arrays.asList(array), Arrays.asList(subArray));
}

代码示例来源:origin: androidannotations/androidannotations

public static void assertGeneratedClassContains(File output, String[] codeFragment) {
  assertTrue("Code fragment \"" + join(codeFragment) + "\" should be in file " + output.getAbsolutePath(),
      Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) != -1);
}

代码示例来源:origin: androidannotations/androidannotations

public static void assertGeneratedClassDoesNotContain(File output, String[] codeFragment) {
  assertTrue("Code fragment \"" + join(codeFragment) + "\" should not be in file " + output.getAbsolutePath(),
      Collections.indexOfSubList(Arrays.asList(getContents(output)), Arrays.asList(codeFragment)) == -1);
}

代码示例来源:origin: stackoverflow.com

int startIdx = Collections.indexOfSubList(arrayList, subSetArrayList);
if (-1 != startIdx)
{
  int endIdx = startIdx + subSetArrayList.size() - 1;
}

代码示例来源:origin: de.dentrassi.eclipse.neoscada.hmi/org.eclipse.scada.vi.ui.user

private boolean isSubChain ( final List<ViewInstanceDescriptor> descriptors )
{
  if ( this.currentChain == null || this.currentChain.isEmpty () )
  {
    return false;
  }
  final int idx = Collections.indexOfSubList ( this.currentChain, descriptors );
  return idx >= 0;
}

代码示例来源:origin: stackoverflow.com

int a [] = {4,2,1,4,2,1};
if(Collections.indexOfSubList(list, Arrays.asList(a))!=-1){
    return true;
}
return false

代码示例来源:origin: stackoverflow.com

Byte[] needle = { 68, 73, 67, 77 };
Byte[] hayStack = { 00, 01, 68, 73, 67, 77, 11, 45 };
location = Collections.indexOfSubList(Arrays.asList(hayStack),
  Arrays.asList(needle));

// location now equals 2

代码示例来源:origin: stackoverflow.com

public static boolean arraysMatch(int[] array1, int[] array2) {
  return Collections.indexOfSubList(
    Arrays.asList(ArrayUtils.toObject(ArrayUtils.addAll(array2, array2))),
    Arrays.asList(ArrayUtils.toObject(array1))
  ) != -1;
}

代码示例来源:origin: stackoverflow.com

List<Integer> nums = new ArrayList<>();
List<Integer> target = new ArrayList<>(Arrays.asList(new int[]{1, 3, 1}));
for (int i : array) {
  if (i == 3 || i == 1) {
    nums.add(i);
  }
}
return Collections.indexOfSubList(nums, target) >= 0;

代码示例来源:origin: stackoverflow.com

public static boolean arraysMatch(int[] array1, int[] array2) {
  int[] combined = new int[array2.length * 2];
  System.arraycopy(array2, 0, combined, 0, array2.length);
  System.arraycopy(array2, 0, combined, array2.length, array2.length);
  return Collections.indexOfSubList(Arrays.asList(combined), Arrays.asList(array1)) != -1;
}

代码示例来源:origin: stackoverflow.com

public static boolean arraysMatch(int[] array1, int[] array2) {
  List<Integer> combined = new ArrayList<>(array2.length * 2);
  List<Integer> array2List = Arrays.asList(array2);
  combined.addAll(array2List);
  combined.addAll(array2List);
  return Collections.indexOfSubList(combined, Arrays.asList(array1)) != -1;
}

代码示例来源:origin: stackoverflow.com

List arrlistsrc = new ArrayList();
List arrlisttarget = new ArrayList();

arrlistsrc.add("A");
arrlistsrc.add("B");
arrlistsrc.add("C");

arrlisttarget.add("A");
arrlisttarget.add("C");

int index = Collections.indexOfSubList(arrlistsrc, arrlisttarget); // this will be -1

代码示例来源:origin: stackoverflow.com

List<Byte> fileArr = new ArrayList(Arrays.asList(new Byte[]{1, 2, 3, 4, 5, 6}));
 List<Byte> toReplace = Arrays.asList(new Byte[]{3, 4});
 List<Byte> replacing = Arrays.asList(new Byte[]{13, 14, 15, 16, 17, 18});
 int idx = Collections.indexOfSubList(fileArr, toReplace);
 if (idx >= 0) {
   List<Byte> window = fileArr.subList(idx, idx + toReplace.size());
   window.clear();
   window.addAll(replacing);
 }
 System.out.println(fileArr);
 [1, 2, 13, 14, 15, 16, 17, 18, 5, 6]

代码示例来源:origin: com.atlassian.jira/jira-tests

@Override
protected boolean matchesSafely(final List<T> items, final Description mismatchDescription)
{
  final boolean hasSubsequence = Collections.indexOfSubList(items, expectedElements) != -1;
  if (!hasSubsequence)
  {
    mismatchDescription.appendText("input was ").appendValueList("[", ",", "]", items);
  }
  return hasSubsequence;
}

代码示例来源:origin: stackoverflow.com

int firstIndex = Collections.indexOfSubList(source, target);
 if (firstIndex == -1 ){
   // the sublist doesn't exist
 }
 int lastIndex = Collections.lastIndexOfSubList(source, target);

代码示例来源:origin: stackoverflow.com

public static void removeAllSubList(List<?> list, List<?> subList) {
  // find first occurrence of the subList in the list, O(nm)
  int i = Collections.indexOfSubList(list, subList);
  // if found
  if (i != -1) {
    // bulk remove, O(m)
    list.subList(i, i + subList.size()).clear();
    // recurse with the rest of the list
    removeAllSubList(list.subList(i, list.size()), subList);
  }
}

代码示例来源:origin: stackoverflow.com

private static boolean subs(int[] array, int[] subsequence) {
  return Collections.indexOfSubList(toList(array), toList(subsequence)) >= 0;
}

private static List<Integer> toList(int[] array) {
  List<Integer> list = new ArrayList<>(array.length);
  for (int num : array) {
    list.add(num);
  }
  return list;
}

代码示例来源:origin: labsai/EDDI

private ExecutionState evaluateActions(IData<List<String>> data) {
  List<String> actions = Collections.emptyList();
  if (data != null && data.getResult() != null) {
    actions = data.getResult();
  }
  if (isActionEmpty(actions) ||
      Collections.indexOfSubList(actions, this.actions) > -1) {
    return SUCCESS;
  } else {
    return FAIL;
  }
}

代码示例来源:origin: labsai/EDDI

private ExecutionState evaluateInputExpressions(IData<String> data) {
  List<Expression> inputExpressions = Collections.emptyList();
  if (data != null && data.getResult() != null) {
    inputExpressions = expressionProvider.parseExpressions(data.getResult());
  }
  if (isInputEmpty(inputExpressions) ||
      Collections.indexOfSubList(inputExpressions, expressions) > -1) {
    return SUCCESS;
  } else {
    return FAIL;
  }
}

相关文章

微信公众号

最新文章

更多

Collections类方法