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

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

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

ArrayList.clone介绍

[英]Returns a new ArrayList with the same elements, the same size and the same capacity as this ArrayList.
[中]返回与此ArrayList具有相同元素、相同大小和相同容量的新ArrayList。

代码示例

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

public static int f(ArrayList list) {
    ArrayList workingList = (ArrayList) list.clone();
    Iterator iter = workingList != null ? workingList.iterator() : null;
    return workingList.size();
  }
}

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

/**
 * Appends the specified element to the end of this list.
 *
 * @param element The element to be appended
 */
public boolean add(Object element) {
  if (fast) {
    synchronized (this) {
      ArrayList temp = (ArrayList) list.clone();
      boolean result = temp.add(element);
      list = temp;
      return (result);
    }
  } else {
    synchronized (list) {
      return (list.add(element));
    }
  }
}

代码示例来源:origin: lingochamp/okdownload

public long getTotalOffset() {
  long offset = 0;
  ArrayList<BlockInfo> list = (ArrayList<BlockInfo>) ((ArrayList) blockInfoList).clone();
  final int count = list.size();
  for (int i = 0; i < count; i++) {
    final BlockInfo info = list.get(i);
    offset += info.getCurrentOffset();
  }
  return offset;
}

代码示例来源:origin: commonsguy/cw-omnibus

/**
 * Called internally to start an animation by adding it to the active animations list. Must be
 * called on the UI thread.
 */
private void startAnimation() {
  initAnimation();
  sAnimations.get().add(this);
  if (mStartDelay > 0 && mListeners != null) {
    // Listeners were already notified in start() if startDelay is 0; this is
    // just for delayed animations
    ArrayList<AnimatorListener> tmpListeners =
        (ArrayList<AnimatorListener>) mListeners.clone();
    int numListeners = tmpListeners.size();
    for (int i = 0; i < numListeners; ++i) {
      tmpListeners.get(i).onAnimationStart(this);
    }
  }
}

代码示例来源:origin: cmusphinx/sphinx4

Path cur = paths.get(s);
    p.setCost(cur.getCost());
    p.setPath((ArrayList<String>) cur.getPath().clone());
      String phone = symsArray[i];
      if (!skipSeqs.contains(phone)) {
        p.getPath().add(phone);
  res.add(path);
int numPaths = res.size();
for (int i = nbest; i < numPaths; i++) {
  res.remove(res.size() - 1);

代码示例来源:origin: com.thoughtworks.xstream/xstream

&& parameterTypes.length + k - j <= typedDependencies.length; k++) {
if (parameterTypes[j].isAssignableFrom(typedDependencies[k].type)) {
  matchingDependencies.add(typedDependencies[k].value);
  usedDeps |= 1L << k;
  if (++j == parameterTypes.length) {
    matchingDependencies.add(deps[assignable].value);
    usedDeps |= 1L << assignable;
  possibleMatchingDependencies = (List)matchingDependencies.clone();
  possibleUsedDeps = usedDeps;

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

String[] array = new String[10];
array[0] = "111";
ArrayList one = new ArrayList(); 
one.add(array);
ArrayList two = (ArrayList) one.clone(); //Alternate with: ArrayList two = one;
String[] stringarray1 = (String[]) one.get(0);
String[] stringarray2 = (String[]) two.get(0);
System.out.println("Array: "+one+" with value: "+stringarray1[0]);
System.out.println("Array: "+one+" with value: "+stringarray2[0]);
array[0] = "999";
String[] stringarray3 = (String[]) one.get(0);
String[] stringarray4 = (String[]) two.get(0);
System.out.println("Array: "+one+" with value: "+stringarray3[0]);
System.out.println("Array: "+two+" with value: "+stringarray4[0]);

代码示例来源:origin: commonsguy/cw-omnibus

if (animations.size() > 0 || delayedAnims.size() > 0) {
  callAgain = false;
while (pendingAnimations.size() > 0) {
  ArrayList<ValueAnimator> pendingCopy =
      (ArrayList<ValueAnimator>) pendingAnimations.clone();
  pendingAnimations.clear();
  int count = pendingCopy.size();
  for (int i = 0; i < count; ++i) {
    ValueAnimator anim = pendingCopy.get(i);
      delayedAnims.add(anim);
int numDelayedAnims = delayedAnims.size();
for (int i = 0; i < numDelayedAnims; ++i) {
  ValueAnimator anim = delayedAnims.get(i);
  if (anim.delayedAnimationFrame(currentTime)) {
    readyAnims.add(anim);
  ValueAnimator anim = animations.get(i);
  if (anim.animationFrame(currentTime)) {
    endingAnims.add(anim);
  if (animations.size() == numAnims) {

代码示例来源:origin: commonsguy/cw-omnibus

/**
 * Called internally to end an animation by removing it from the animations list. Must be
 * called on the UI thread.
 */
private void endAnimation() {
  sAnimations.get().remove(this);
  sPendingAnimations.get().remove(this);
  sDelayedAnims.get().remove(this);
  mPlayingState = STOPPED;
  if (mRunning && mListeners != null) {
    ArrayList<AnimatorListener> tmpListeners =
        (ArrayList<AnimatorListener>) mListeners.clone();
    int numListeners = tmpListeners.size();
    for (int i = 0; i < numListeners; ++i) {
      tmpListeners.get(i).onAnimationEnd(this);
    }
  }
  mRunning = false;
  mStarted = false;
}

代码示例来源:origin: ch.unibas.cs.gravis/scalismo-native-stub

@Override
public final void addKeyListener(int index, final KeyListener l) {
  if(l == null) {
    return;
  }
  @SuppressWarnings("unchecked")
  final
  ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
  if(0>index) {
    index = clonedListeners.size();
  }
  clonedListeners.add(index, l);
  keyListeners = clonedListeners;
}

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

/**
 * Insert the specified element at the specified position in this list,
 * and shift all remaining elements up one position.
 *
 * @param index Index at which to insert this element
 * @param element The element to be inserted
 *
 * @exception IndexOutOfBoundsException if the index is out of range
 */
public void add(int index, Object element) {
  if (fast) {
    synchronized (this) {
      ArrayList temp = (ArrayList) list.clone();
      temp.add(index, element);
      list = temp;
    }
  } else {
    synchronized (list) {
      list.add(index, element);
    }
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

mTerminated = true;
if (isStarted()) {
  if (mSortedNodes.size() != mNodes.size()) {
    mDelayAnim.cancel();
  if (mSortedNodes.size() > 0) {
    for (Node node : mSortedNodes) {
      node.animation.end();
        (ArrayList<AnimatorListener>) mListeners.clone();
    for (AnimatorListener listener : tmpListeners) {
      listener.onAnimationEnd(this);

代码示例来源:origin: commonsguy/cw-omnibus

mStarted = true;
mStartedDelay = false;
sPendingAnimations.get().add(this);
if (mStartDelay == 0) {
        (ArrayList<AnimatorListener>) mListeners.clone();
    int numListeners = tmpListeners.size();
    for (int i = 0; i < numListeners; ++i) {
      tmpListeners.get(i).onAnimationStart(this);

代码示例来源:origin: andkulikov/Transitions-Everywhere

/**
 * This method is called automatically by the transition and
 * TransitionSet classes prior to a Transition subclass starting;
 * subclasses should not need to call it directly.
 *
 * @hide
 */
protected void start() {
  if (mNumInstances == 0) {
    if (mListeners != null && mListeners.size() > 0) {
      ArrayList<TransitionListener> tmpListeners =
          (ArrayList<TransitionListener>) mListeners.clone();
      int numListeners = tmpListeners.size();
      for (int i = 0; i < numListeners; ++i) {
        tmpListeners.get(i).onTransitionStart(this);
      }
    }
    mEnded = false;
  }
  mNumInstances++;
}

代码示例来源:origin: org.jogamp.jogl/jogl-all-noawt

@Override
public final void addKeyListener(int index, final KeyListener l) {
  if(l == null) {
    return;
  }
  @SuppressWarnings("unchecked")
  final
  ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
  if(0>index) {
    index = clonedListeners.size();
  }
  clonedListeners.add(index, l);
  keyListeners = clonedListeners;
}

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

/**
 * Appends the specified element to the end of this list.
 *
 * @param element The element to be appended
 */
public boolean add(Object element) {
  if (fast) {
    synchronized (this) {
      ArrayList temp = (ArrayList) list.clone();
      boolean result = temp.add(element);
      list = temp;
      return (result);
    }
  } else {
    synchronized (list) {
      return (list.add(element));
    }
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

ArrayList<AnimatorListener> tmpListeners = null;
if (mListeners != null) {
  tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
  for (AnimatorListener listener : tmpListeners) {
    listener.onAnimationCancel(this);
} else  if (mSortedNodes.size() > 0) {
  for (Node node : mSortedNodes) {
    node.animation.cancel();

代码示例来源:origin: commonsguy/cw-omnibus

int numSortedNodes = mSortedNodes.size();
for (int i = 0; i < numSortedNodes; ++i) {
  Node node = mSortedNodes.get(i);
  if (oldListeners != null && oldListeners.size() > 0) {
    final ArrayList<AnimatorListener> clonedListeners = new
        ArrayList<AnimatorListener>(oldListeners);
  Node node = mSortedNodes.get(i);
  if (mSetListener == null) {
    mSetListener = new AnimatorSetListener(this);
    node.tmpDependencies = (ArrayList<Dependency>) node.dependencies.clone();
  for (Node node : nodesToStart) {
    node.animation.start();
    mPlayingSet.add(node.animation);
      (ArrayList<AnimatorListener>) mListeners.clone();
  int numListeners = tmpListeners.size();
  for (int i = 0; i < numListeners; ++i) {
  if (mListeners != null) {
    ArrayList<AnimatorListener> tmpListeners =
        (ArrayList<AnimatorListener>) mListeners.clone();
    int numListeners = tmpListeners.size();
    for (int i = 0; i < numListeners; ++i) {

代码示例来源:origin: andkulikov/Transitions-Everywhere

/**
 * This method cancels a transition that is currently running.
 *
 * @hide
 */
protected void cancel() {
  int numAnimators = mCurrentAnimators.size();
  for (int i = numAnimators - 1; i >= 0; i--) {
    Animator animator = mCurrentAnimators.get(i);
    animator.cancel();
  }
  if (mListeners != null && mListeners.size() > 0) {
    ArrayList<TransitionListener> tmpListeners =
        (ArrayList<TransitionListener>) mListeners.clone();
    int numListeners = tmpListeners.size();
    for (int i = 0; i < numListeners; ++i) {
      tmpListeners.get(i).onTransitionCancel(this);
    }
  }
}

代码示例来源:origin: ch.unibas.cs.gravis/scalismo-native-stub

@Override
public final void addMouseListener(int index, final MouseListener l) {
  if(l == null) {
    return;
  }
  @SuppressWarnings("unchecked")
  final
  ArrayList<MouseListener> clonedListeners = (ArrayList<MouseListener>) mouseListeners.clone();
  if(0>index) {
    index = clonedListeners.size();
  }
  clonedListeners.add(index, l);
  mouseListeners = clonedListeners;
}

相关文章

微信公众号

最新文章

更多