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

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

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

ArrayList.remove介绍

[英]Removes the object at the specified location from this list.
[中]从此列表中删除指定位置处的对象。

代码示例

canonical example by Tabnine

private void usingArrayList() {
 ArrayList<String> list = new ArrayList<>(Arrays.asList("cat", "cow", "dog"));
 list.add("fish");
 int size = list.size(); // size = 4
 list.set(size - 1, "horse"); // replacing the last element to "horse"
 String removed = list.remove(1); // removed = "cow"
 String second = list.get(1); // second = "dog"
}

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

State popStack() {
  return _stateStack.remove(_stateStack.size() - 1);
}

代码示例来源:origin: facebook/stetho

public synchronized boolean unregister(PathMatcher path, HttpHandler handler) {
 int index = mPathMatchers.indexOf(path);
 if (index >= 0) {
  if (handler == mHttpHandlers.get(index)) {
   mPathMatchers.remove(index);
   mHttpHandlers.remove(index);
   return true;
  }
 }
 return false;
}

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

private void removeFixedViewInfo(View v, ArrayList<FixedViewInfo> where) {
  int len = where.size();
  for (int i = 0; i < len; ++i) {
    FixedViewInfo info = where.get(i);
    if (info.view == v) {
      where.remove(i);
      break;
    }
  }
}

代码示例来源:origin: alibaba/jstorm

private ArrayList<Integer> rotating_random_range(int amt) {
  ArrayList<Integer> range = new ArrayList<>();
  for (int i = 0; i < amt; i++) {
    range.add(i);
  }
  ArrayList<Integer> rtn = new ArrayList<>();
  for (int i = 0; i < amt; i++) {
    int index = (int) (Math.random() * range.size());
    rtn.add(range.remove(index));
  }
  return rtn;
}

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

/** Concurrent modification bug */

  public static void main(String[] args) {
    ArrayList<String> namesList = new ArrayList<String>();

    namesList.add("Kelly");
    namesList.add("John");
    namesList.add("Peter");
    namesList.add("Rose");

    for (Iterator<String> i = namesList.iterator(); i.hasNext(); ) {
      String name = i.next();
      if (name.equals("Peter")) {
        namesList.remove(name);
      } else {
        System.out.println(name);
      }
    }
  }
}

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

@Implementation(minSdk = LOLLIPOP)
protected void addAction(AccessibilityAction action) {
 if (action == null) {
  return;
 }
 if (actionsArray == null) {
  actionsArray = new ArrayList<>();
 }
 actionsArray.remove(action);
 actionsArray.add(action);
}

代码示例来源:origin: ankidroid/Anki-Android

@Override
  public String[] transform(String[] fields) {
    ArrayList<String> fl = new ArrayList<>(Arrays.asList(fields));
    fl.remove(idx);
    return fl.toArray(new String[fl.size()]);
  }
}

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

System.out.println("******* Distinct shapes found using AbstractionGrid *******");
  Iterator dit = boundarySetsStep1.iterator();
  while (dit.hasNext()) {
    set.printAsGrid();
  System.out.println("******* Same set of shapes after processing them by filling *******");
ArrayList boundarySetsStep2 = new ArrayList();
Iterator boundarySetIt = boundarySetsStep1.iterator();
while (boundarySetIt.hasNext()) {
          System.out.println("-----------------------------------");
ArrayList open = new ArrayList();
ArrayList closed = new ArrayList();
if(mixed.size() > 0 && closed.size() > 0) {
      boundarySetsStep2.remove(set);
      boundarySetsStep2.addAll(set.breakIntoDistinctBoundaries(workGrid));
  while(sets.hasNext()){
    CellSet set = (CellSet) sets.next();
    boundarySetsStep2.remove(set);
    boundarySetsStep2.addAll(set.breakTrulyMixedBoundaries(workGrid));

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

@Override
public synchronized E remove(int index) {
 ArrayList<E> newList = new ArrayList<>(list);
 // Removals in ArrayList won't break sorting
 E result = newList.remove(index);
 list = Collections.unmodifiableList(newList);
 return result;
}

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

@Override
 public void remove() {
  if (!this.nextWasCalled) {
   throw new IllegalStateException("No element to remove");
  }
  this.nextWasCalled = false;
  List<HStoreFile> src = components.get(currentComponent);
  if (src instanceof ImmutableList<?>) {
   src = new ArrayList<>(src);
   components.set(currentComponent, src);
  }
  src.remove(indexWithinComponent);
  --size;
  --indexWithinComponent;
  if (src.isEmpty()) {
   components.remove(currentComponent); // indexWithinComponent is already -1 here.
  }
 }
}

代码示例来源:origin: deathmarine/Luyten

public static void add(String path) {
  if (paths.contains(path)) {
    paths.remove(path);
    paths.add(path);
    return;
  }
  
  if (paths.size() >= 10) paths.remove(0);
  paths.add(path);
  
  save();
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void manageObservers(Handler handler, boolean add) {
  synchronized (mEchoObservers) {
    if (add) {
      mEchoObservers.add(handler);
    } else {
      mEchoObservers.remove(handler);
    }
  }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Adds a new weighted value.
 *
 * @param weight The weight of the new observation.
 * @param value The value of the new observation.
 */
public void addSample(int weight, float value) {
 ensureSortedByIndex();
 Sample newSample = recycledSampleCount > 0 ? recycledSamples[--recycledSampleCount]
   : new Sample();
 newSample.index = nextSampleIndex++;
 newSample.weight = weight;
 newSample.value = value;
 samples.add(newSample);
 totalWeight += weight;
 while (totalWeight > maxWeight) {
  int excessWeight = totalWeight - maxWeight;
  Sample oldestSample = samples.get(0);
  if (oldestSample.weight <= excessWeight) {
   totalWeight -= oldestSample.weight;
   samples.remove(0);
   if (recycledSampleCount < MAX_RECYCLED_SAMPLES) {
    recycledSamples[recycledSampleCount++] = oldestSample;
   }
  } else {
   oldestSample.weight -= excessWeight;
   totalWeight -= excessWeight;
  }
 }
}

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

/**
 * Removes a collection from the those being decorated in this composite.
 *
 * @param coll  collection to be removed
 */
public void removeComposited(Collection coll) {
  ArrayList list = new ArrayList(this.all.length);
  list.addAll(Arrays.asList(this.all));
  list.remove(coll);
  this.all = (Collection[]) list.toArray(new Collection[list.size()]);
}

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

public void run() {
  String maryBase = System.getProperty("mary.base");
  System.out.println("Installing " + name + "-" + version + " in " + maryBase + "...");
  ArrayList<String> files = new ArrayList<String>();
  try {
    ZipFile zipfile = new ZipFile(archiveFile);
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      files.add(entry.getName()); // add to installed filelist; rely on uninstaller retaining shared files
      File newFile = new File(maryBase + "/" + entry.getName());
      if (entry.isDirectory()) {
        System.err.println("Extracting directory: " + entry.getName());
        newFile.mkdir();
      } else {
              files.remove(entry.getName());
            System.err.println("NOT overwriting existing newer file: " + entry.getName());
            continue;

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

ArrayList<String> list = new ArrayList<String>();     
JSONArray jsonArray = (JSONArray)jsonObject; 
int len = jsonArray.length();
if (jsonArray != null) { 
  for (int i=0;i<len;i++){ 
  list.add(jsonArray.get(i).toString());
  } 
}
//Remove the element from arraylist
list.remove(position);
//Recreate JSON Array
JSONArray jsArray = new JSONArray(list);

代码示例来源:origin: EsotericSoftware/kryonet

void removeConnection (Connection connection) {
  ArrayList<Connection> temp = new ArrayList(Arrays.asList(connections));
  temp.remove(connection);
  connections = temp.toArray(new Connection[temp.size()]);
  pendingConnections.remove(connection.id);
}

代码示例来源:origin: facebook/stetho

private static <T> boolean removeFromWeakList(ArrayList<WeakReference<T>> haystack, T needle) {
 for (int i = 0, N = haystack.size(); i < N; i++) {
  T hay = haystack.get(i).get();
  if (hay == needle) {
   haystack.remove(i);
   return true;
  }
 }
 return false;
}

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

@Override
public synchronized boolean remove(Object o) {
 ArrayList<E> newList = new ArrayList<>(list);
 // Removals in ArrayList won't break sorting
 boolean changed = newList.remove(o);
 list = Collections.unmodifiableList(newList);
 return changed;
}

相关文章

微信公众号

最新文章

更多