java.util.ArrayList.listIterator()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(205)

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

ArrayList.listIterator介绍

[英]Returns a list iterator over the elements in this list (in proper sequence).

The returned list iterator is fail-fast.
[中]返回此列表中元素的列表迭代器(按正确顺序)。
返回的列表迭代器是fail-fast

代码示例

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

static AttributeInfo lookup(ArrayList list, String name) {
  if (list == null)
    return null;
  ListIterator iterator = list.listIterator();
  while (iterator.hasNext()) {
    AttributeInfo ai = (AttributeInfo)iterator.next();
    if (ai.getName().equals(name))
      return ai;
  }
  return null;            // no such attribute
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testEmptyList() throws Exception {
  ArrayList list = new ArrayList(EMPTY_SET);
  assertEquals(0,list.size());
  assertEquals(true,list.isEmpty());
  assertEquals(false,list.contains(1));
  assertEquals(false,list.iterator().hasNext());
  ListIterator it = list.listIterator();
  assertEquals(false, it.hasNext());
  assertEquals(-1, it.previousIndex());
  assertEquals(0, it.nextIndex());
}
@Test

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testSingleList() throws Exception {
  ArrayList list = new ArrayList(singleton(1));
  assertEquals(1,list.size());
  assertEquals(false,list.isEmpty());
  assertEquals(true,list.contains(1));
  assertEquals(false,list.contains(0));
  assertEquals(true,list.iterator().hasNext());
  assertEquals(1,list.iterator().next());
  ListIterator it = list.listIterator();
  assertEquals(true, it.hasNext());
  assertEquals(-1, it.previousIndex());
  assertEquals(0, it.nextIndex());
  assertEquals(1, it.next());
  assertEquals(0, it.previousIndex());
  assertEquals(1, it.nextIndex());
  assertEquals(true, it.hasPrevious());
  assertEquals(1, it.previous());
  assertEquals(1, it.next());
  assertEquals(false, it.hasNext());
}

代码示例来源:origin: EvoSuite/evosuite

public void testMe(ArrayList<Integer> integerList, int index) {
    ListIterator<Integer> litr = integerList.listIterator(index);
    int element = litr.next();
  }
}

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

static synchronized AttributeInfo remove(ArrayList list, String name) {
  if (list == null)
    return null;
  AttributeInfo removed = null;
  ListIterator iterator = list.listIterator();
  while (iterator.hasNext()) {
    AttributeInfo ai = (AttributeInfo)iterator.next();
    if (ai.getName().equals(name)) {
      iterator.remove();
      removed = ai;
    }
  }
  return removed;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

assertEquals(2, it.next());
assertEquals(false, it.hasNext());
ListIterator li = list.listIterator();
assertEquals(true, li.hasNext());
assertEquals(-1, li.previousIndex());
assertEquals(0, li.nextIndex());
assertEquals(1, li.next());
assertEquals(0, li.previousIndex());
assertEquals(1, li.nextIndex());
assertEquals(true, li.hasPrevious());
assertEquals(1, li.previous());
assertEquals(1, li.next());
assertEquals(true, li.hasNext());
assertEquals(0, li.previousIndex());
assertEquals(1, li.nextIndex());
assertEquals(2, li.next());
assertEquals(1, li.previousIndex());
assertEquals(2, li.nextIndex());
assertEquals(true, li.hasPrevious());
assertEquals(false, li.hasNext());
assertEquals(2, li.previous());

代码示例来源:origin: hankcs/HanLP

/**
 * 随机挑一个近义词
 * @param type 类型
 * @return
 */
public Synonym randomSynonym(Type type, String preWord)
{
  ArrayList<Synonym> synonymArrayList = new ArrayList<Synonym>(synonymList);
  ListIterator<Synonym> listIterator = synonymArrayList.listIterator();
  if (type != null) while (listIterator.hasNext())
  {
    Synonym synonym = listIterator.next();
    if (synonym.type != type || (preWord != null && CoreBiGramTableDictionary.getBiFrequency(preWord, synonym.realWord) == 0)) listIterator.remove();
  }
  if (synonymArrayList.size() == 0) return null;
  return synonymArrayList.get((int) (System.currentTimeMillis() % (long)synonymArrayList.size()));
}

代码示例来源:origin: org.jvnet.hudson.hadoop/hadoop-core

private void toString(ArrayList resources, StringBuffer sb) {
 ListIterator i = resources.listIterator();
 while (i.hasNext()) {
  if (i.nextIndex() != 0) {
   sb.append(", ");
  }
  sb.append(i.next());
 }
}

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

private void testExistingField(String name, String descriptor)
    throws DuplicateMemberException {
  ListIterator it = fields.listIterator(0);
  while (it.hasNext()) {
    FieldInfo minfo = (FieldInfo)it.next();
    if (minfo.getName().equals(name))
      throw new DuplicateMemberException("duplicate field: " + name);
  }
}

代码示例来源:origin: net.wetheinter/xapi-core-collect

@Override
public Map<Integer, E> toMap(Map<Integer, E> into) {
 if (into == null) {
  into = newMap();
 }
 ListIterator<E> iter = list.listIterator();
 while (iter.hasNext()) {
  into.put(iter.nextIndex(), iter.next());
 }
 return into;
}

代码示例来源:origin: scouter-project/scouter

static AttributeInfo lookup(ArrayList list, String name) {
  if (list == null)
    return null;
  ListIterator iterator = list.listIterator();
  while (iterator.hasNext()) {
    AttributeInfo ai = (AttributeInfo)iterator.next();
    if (ai.getName().equals(name))
      return ai;
  }
  return null;            // no such attribute
}

代码示例来源:origin: scouter-project/scouter

static synchronized AttributeInfo remove(ArrayList list, String name) {
  if (list == null)
    return null;
  AttributeInfo removed = null;
  ListIterator iterator = list.listIterator();
  while (iterator.hasNext()) {
    AttributeInfo ai = (AttributeInfo)iterator.next();
    if (ai.getName().equals(name)) {
      iterator.remove();
      removed = ai;
    }
  }
  return removed;
}

代码示例来源:origin: org.freemarker/freemarker

@Override
protected Expression deepCloneWithIdentifierReplaced_inner(
    String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) {
  ArrayList clonedValues = (ArrayList) items.clone();
  for (ListIterator iter = clonedValues.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  return new ListLiteral(clonedValues);
}

代码示例来源:origin: Sable/soot

public boolean add(Object toadd) {
 if (contains(toadd)) {
  return false;
 }
 /* it is not added to the end, but keep it in the order */
 int index = fulllist.indexOf(toadd);
 for (ListIterator worklistIter = worklist.listIterator(); worklistIter.hasNext();) {
  Object tocomp = worklistIter.next();
  int tmpidx = fulllist.indexOf(tocomp);
  if (index < tmpidx) {
   worklistIter.add(toadd);
   return true;
  }
 }
 return false;
}

代码示例来源:origin: commons-collections/commons-collections

ListIterator li1 = list.listIterator();
  ListIterator li2 = lo.listIterator();
  while (li1.hasNext() && li2.hasNext()) {
    Object o1 = li1.next();
    Object o2 = li2.next();
    if (!(o1 == null ? o2 == null : o1.equals(o2)))
      return (false);
  return (!(li1.hasNext() || li2.hasNext()));
} else {
  synchronized (list) {
    ListIterator li1 = list.listIterator();
    ListIterator li2 = lo.listIterator();
    while (li1.hasNext() && li2.hasNext()) {
      Object o1 = li1.next();
      Object o2 = li2.next();
      if (!(o1 == null ? o2 == null : o1.equals(o2)))

代码示例来源:origin: scouter-project/scouter

private void testExistingField(String name, String descriptor)
    throws DuplicateMemberException {
  ListIterator it = fields.listIterator(0);
  while (it.hasNext()) {
    FieldInfo minfo = (FieldInfo)it.next();
    if (minfo.getName().equals(name))
      throw new DuplicateMemberException("duplicate field: " + name);
  }
}

代码示例来源:origin: org.freemarker/freemarker

@Override
protected Expression deepCloneWithIdentifierReplaced_inner(
    String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) {
  ArrayList clonedKeys = (ArrayList) keys.clone();
  for (ListIterator iter = clonedKeys.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  ArrayList clonedValues = (ArrayList) values.clone();
  for (ListIterator iter = clonedValues.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  return new HashLiteral(clonedKeys, clonedValues);
}

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

static List<Term> trimLeadingIndent(List<Term> code) {
 ArrayList<Term> result = new ArrayList<>(code);
 ListIterator<Term> it = result.listIterator();
 while (it.hasNext()) {
  Term t = it.next();
  if (t.isWhitespace()) {
   String whitespace = t.toString();
   int indexOf = whitespace.indexOf('\n');
   if (indexOf >= 0) {
    it.set(new Whitespace(whitespace.substring(0, indexOf + 1)));
   }
  }
 }
 return result;
}

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

ListIterator li1 = list.listIterator();
  ListIterator li2 = lo.listIterator();
  while (li1.hasNext() && li2.hasNext()) {
    Object o1 = li1.next();
    Object o2 = li2.next();
    if (!(o1 == null ? o2 == null : o1.equals(o2)))
      return (false);
  return (!(li1.hasNext() || li2.hasNext()));
} else {
  synchronized (list) {
    ListIterator li1 = list.listIterator();
    ListIterator li2 = lo.listIterator();
    while (li1.hasNext() && li2.hasNext()) {
      Object o1 = li1.next();
      Object o2 = li2.next();
      if (!(o1 == null ? o2 == null : o1.equals(o2)))

代码示例来源:origin: apache/incubator-druid

public double cost(DataSegment segment)
{
 double cost = 0.0;
 int index = Collections.binarySearch(intervals, segment.getInterval(), Comparators.intervalsByStartThenEnd());
 index = (index >= 0) ? index : -index - 1;
 for (ListIterator<Bucket> it = sortedBuckets.listIterator(index); it.hasNext(); ) {
  Bucket bucket = it.next();
  if (!bucket.inCalculationInterval(segment)) {
   break;
  }
  cost += bucket.cost(segment);
 }
 for (ListIterator<Bucket> it = sortedBuckets.listIterator(index); it.hasPrevious(); ) {
  Bucket bucket = it.previous();
  if (!bucket.inCalculationInterval(segment)) {
   break;
  }
  cost += bucket.cost(segment);
 }
 return cost;
}

相关文章