本文整理了Java中java.util.ArrayList.clear()
方法的一些代码示例,展示了ArrayList.clear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayList.clear()
方法的具体详情如下:
包路径:java.util.ArrayList
类名称:ArrayList
方法名:clear
[英]Removes all elements from this ArrayList, leaving it empty.
[中]删除此ArrayList中的所有元素,将其保留为空。
代码示例来源:origin: netty/netty
@SuppressWarnings("unchecked")
public <E> ArrayList<E> arrayList(int minCapacity) {
ArrayList<E> list = (ArrayList<E>) arrayList;
if (list == null) {
arrayList = new ArrayList<Object>(minCapacity);
return (ArrayList<E>) arrayList;
}
list.clear();
list.ensureCapacity(minCapacity);
return list;
}
代码示例来源:origin: google/ExoPlayer
private void updateSampleStreams(SampleStream[] streams) {
hlsSampleStreams.clear();
for (SampleStream stream : streams) {
if (stream != null) {
hlsSampleStreams.add((HlsSampleStream) stream);
}
}
}
代码示例来源:origin: google/ExoPlayer
/**
* Returns the {@link DataSpec} instances passed to {@link #open(DataSpec)} since the last call to
* this method.
*/
public final DataSpec[] getAndClearOpenedDataSpecs() {
DataSpec[] dataSpecs = new DataSpec[openedDataSpecs.size()];
openedDataSpecs.toArray(dataSpecs);
openedDataSpecs.clear();
return dataSpecs;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private int[][][][] createPartialDataForLOP(int lopIter, int[][][][] data) {
ArrayList<Integer> newFeatureList = new ArrayList<>(1000);
Set<Integer> featureIndicesSet = featureIndicesSetArray.get(lopIter);
int[][][][] newData = new int[data.length][][][];
for (int i = 0; i < data.length; i++) {
newData[i] = new int[data[i].length][][];
for (int j = 0; j < data[i].length; j++) {
newData[i][j] = new int[data[i][j].length][];
for (int k = 0; k < data[i][j].length; k++) {
int[] oldFeatures = data[i][j][k];
newFeatureList.clear();
for (int oldFeatureIndex : oldFeatures) {
if (featureIndicesSet.contains(oldFeatureIndex)) {
newFeatureList.add(oldFeatureIndex);
}
}
newData[i][j][k] = new int[newFeatureList.size()];
for (int l = 0; l < newFeatureList.size(); ++l) {
newData[i][j][k][l] = newFeatureList.get(l);
}
}
}
}
return newData;
}
代码示例来源:origin: apache/hbase
private void cancelAllChores(final boolean mayInterruptIfRunning) {
ArrayList<ScheduledChore> choresToCancel = new ArrayList<>(scheduledChores.keySet().size());
// Build list of chores to cancel so we can iterate through a set that won't change
// as chores are cancelled. If we tried to cancel each chore while iterating through
// keySet the results would be undefined because the keySet would be changing
for (ScheduledChore chore : scheduledChores.keySet()) {
choresToCancel.add(chore);
}
for (ScheduledChore chore : choresToCancel) {
cancelChore(chore, mayInterruptIfRunning);
}
choresToCancel.clear();
}
代码示例来源:origin: com.h2database/h2
private void applyOffset() {
if (offset <= 0) {
return;
}
if (external == null) {
if (offset >= rows.size()) {
rows.clear();
rowCount = 0;
} else {
// avoid copying the whole array for each row
int remove = Math.min(offset, rows.size());
rows = new ArrayList<>(rows.subList(remove, rows.size()));
rowCount -= remove;
}
} else {
if (offset >= rowCount) {
rowCount = 0;
} else {
diskOffset = offset;
rowCount -= offset;
}
}
distinctRows = null;
}
代码示例来源:origin: novoda/android-demos
public void setInitalPositionMultiPoints(MotionEvent event) {
touchPoints.clear();
int pointerIndex = 0;
for (int index = 0; index < event.getPointerCount(); ++index) {
pointerIndex = event.getPointerId(index);
touchPoints.add(new PointF(event.getX(pointerIndex), event.getY(pointerIndex)));
}
double r = Math.atan2(touchPoints.get(1).x - touchPoints.get(1 - 1).x,
touchPoints.get(1).y - touchPoints.get(1 - 1).y);
old_degrees = -(int) Math.toDegrees(r);
}
代码示例来源:origin: apache/hbase
@Override
public synchronized Optional<CompactionContext> selectCompaction() {
CompactionContext ctx = new TestCompactionContext(new ArrayList<>(notCompacting));
compacting.addAll(notCompacting);
notCompacting.clear();
try {
ctx.select(null, false, false, false);
} catch (IOException ex) {
fail("Shouldn't happen");
}
return Optional.of(ctx);
}
代码示例来源:origin: apache/flink
@Override
public void reduce(Iterable<Tuple2<Long, Long>> values, Collector<Tuple2<Long, Long[]>> out) {
neighbors.clear();
Long id = 0L;
for (Tuple2<Long, Long> n : values) {
id = n.f0;
neighbors.add(n.f1);
}
out.collect(new Tuple2<Long, Long[]>(id, neighbors.toArray(new Long[neighbors.size()])));
}
}
代码示例来源:origin: redisson/redisson
@Override
public void freeAll() {
for (int i = 0; i < allocated.size(); i++) {
MallocBytez mallocBytez = allocated.get(i);
mallocBytez.free();
}
allocated.clear();
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
public void setItems(List<SuggestionItem> items) {
this.items.clear();
if (showSuggestionHistory) {
this.items.addAll(items);
} else {
// remove history items if history is disabled
for (SuggestionItem item : items) {
if (!item.fromHistory) {
this.items.add(item);
}
}
}
notifyDataSetChanged();
}
代码示例来源:origin: H07000223/FlycoTabLayout
public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
if (tabEntitys == null || tabEntitys.size() == 0) {
throw new IllegalStateException("TabEntitys can not be NULL or EMPTY !");
}
this.mTabEntitys.clear();
this.mTabEntitys.addAll(tabEntitys);
notifyDataSetChanged();
}
代码示例来源:origin: aurelhubert/ahbottomnavigation
public DemoAdapter(ArrayList<String> dataset) {
mDataset.clear();
mDataset.addAll(dataset);
}
代码示例来源:origin: hankcs/HanLP
void finish()
{
flush(0);
_units.set(0, _nodes.get(0).unit());
_labels.set(0, _nodes.get(0).label);
_nodes.clear();
_table.clear();
_nodeStack.clear();
_recycleBin.clear();
_isIntersections.build();
}
代码示例来源:origin: ZieIony/Carbon
public ArrayList<MenuItem> getVisibleItems() {
if (!mIsVisibleItemsStale) return mVisibleItems;
// Refresh the visible items
mVisibleItems.clear();
final int itemsSize = mItems.size();
MenuItem item;
for (int i = 0; i < itemsSize; i++) {
item = mItems.get(i);
if (item.isVisible()) mVisibleItems.add(item);
}
mIsVisibleItemsStale = false;
return mVisibleItems;
}
代码示例来源:origin: spotbugs/spotbugs
@NoWarning("NP_")
public static void falsePositive_ifnonull(List lst) {
final ArrayList sections = new ArrayList();
for (Object o : lst) {
if (sections != null)
sections.add(o);
}
sections.clear();
}
代码示例来源:origin: redisson/redisson
@SuppressWarnings("unchecked")
public <E> ArrayList<E> arrayList(int minCapacity) {
ArrayList<E> list = (ArrayList<E>) arrayList;
if (list == null) {
arrayList = new ArrayList<Object>(minCapacity);
return (ArrayList<E>) arrayList;
}
list.clear();
list.ensureCapacity(minCapacity);
return list;
}
代码示例来源:origin: libgdx/libgdx
public GradientPanel (GradientColorValue value, String name, String description, boolean hideGradientEditor) {
super(value, name, description);
this.value = value;
initializeComponents();
if (hideGradientEditor) {
gradientEditor.setVisible(false);
}
gradientEditor.percentages.clear();
for (float percent : value.getTimeline())
gradientEditor.percentages.add(percent);
gradientEditor.colors.clear();
float[] colors = value.getColors();
for (int i = 0; i < colors.length;) {
float r = colors[i++];
float g = colors[i++];
float b = colors[i++];
gradientEditor.colors.add(new Color(r, g, b));
}
if (gradientEditor.colors.isEmpty() || gradientEditor.percentages.isEmpty()) {
gradientEditor.percentages.clear();
gradientEditor.percentages.add(0f);
gradientEditor.percentages.add(1f);
gradientEditor.colors.clear();
gradientEditor.colors.add(Color.white);
}
setColor(gradientEditor.colors.get(0));
}
代码示例来源:origin: apache/hbase
/**
* Reads WALEdit from cells.
* @param cellDecoder Cell decoder.
* @param expectedCount Expected cell count.
* @return Number of KVs read.
*/
public int readFromCells(Codec.Decoder cellDecoder, int expectedCount) throws IOException {
cells.clear();
cells.ensureCapacity(expectedCount);
while (cells.size() < expectedCount && cellDecoder.advance()) {
cells.add(cellDecoder.current());
}
return cells.size();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void update() {
synchronized (eventQueue){
// flush events to listener
for (int i = 0; i < eventQueue.size(); i++){
listener.onKeyEvent(eventQueue.get(i));
}
eventQueue.clear();
}
}
内容来源于网络,如有侵权,请联系作者删除!