本文整理了Java中java.util.ArrayList.size()
方法的一些代码示例,展示了ArrayList.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayList.size()
方法的具体详情如下:
包路径:java.util.ArrayList
类名称:ArrayList
方法名:size
[英]The number of elements in 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
/**
* Adds a list/map reference.
*/
@Override
public int addRef(Object ref) {
if (_refs == null)
_refs = new ArrayList();
_refs.add(ref);
return _refs.size() - 1;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void add(int index, T element) {
list.add(index, element);
lazySet(list.size());
}
代码示例来源:origin: stackoverflow.com
// Substitute appropriate type.
ArrayList<...> a = new ArrayList<...>();
// Add elements to list.
// Generate an iterator. Start just after the last element.
ListIterator li = a.listIterator(a.size());
// Iterate in reverse.
while(li.hasPrevious()) {
System.out.println(li.previous());
}
代码示例来源:origin: stackoverflow.com
public class SortedList<E> extends AbstractList<E> {
private ArrayList<E> internalList = new ArrayList<E>();
// Note that add(E e) in AbstractList is calling this one
@Override
public void add(int position, E e) {
internalList.add(e);
Collections.sort(internalList, null);
}
@Override
public E get(int i) {
return internalList.get(i);
}
@Override
public int size() {
return internalList.size();
}
}
代码示例来源:origin: google/ExoPlayer
private List<Cue> getDisplayCues() {
List<Cue> displayCues = new ArrayList<>();
for (int i = 0; i < cueBuilders.size(); i++) {
Cue cue = cueBuilders.get(i).build();
if (cue != null) {
displayCues.add(cue);
}
}
return displayCues;
}
代码示例来源:origin: google/guava
@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListWithDifferentElements() {
ArrayList<E> other = new ArrayList<>(getSampleElements());
other.set(other.size() / 2, getSubjectGenerator().samples().e3());
assertFalse(
"A List should not equal another List containing different elements.",
getList().equals(other));
}
代码示例来源:origin: scouter-project/scouter
public void printCRUD() {
do {
System.out.print("type:" + sqlNode.type.toString() + "-->");
for (int i = 0; i < sqlNode.tableList.size(); i++) {
System.out.print(sqlNode.tableList.get(i) + " ");
}
System.out.println();
sqlNode = sqlNode.nextNode;
} while (sqlNode != null);
}
代码示例来源:origin: stanfordnlp/CoreNLP
protected ArrayList<Integer> scanForPronouns(ArrayList<Pair<Integer, Integer>> nonQuoteRuns) {
ArrayList<Integer> pronounList = new ArrayList<>();
for(int run_index = 0; run_index < nonQuoteRuns.size(); run_index++)
pronounList.addAll(scanForPronouns(nonQuoteRuns.get(run_index)));
return pronounList;
}
代码示例来源:origin: apache/flink
/**
* Increases the result vector component at the specified position by the specified delta.
*/
private void updateResultVector(int position, int delta) {
// inflate the vector to contain the given position
while (this.resultVector.size() <= position) {
this.resultVector.add(0);
}
// increment the component value
final int component = this.resultVector.get(position);
this.resultVector.set(position, component + delta);
}
代码示例来源:origin: FudanNLP/fnlp
private void initBaseDist() {
for (int i = 0; i < classCenter.size(); i++) {
float base = getBaseDist(i);
baseDistList.add(base);
}
System.out.println("Finish init base distance list");
}
代码示例来源:origin: redisson/redisson
public CtField[] getFields() {
ArrayList alist = new ArrayList();
getFields(alist, this);
return (CtField[])alist.toArray(new CtField[alist.size()]);
}
代码示例来源:origin: libgdx/libgdx
public void mouseDragged (MouseEvent event) {
if (dragIndex == -1 || dragIndex == 0 || dragIndex == percentages.size() - 1) return;
float percent = (event.getX() - gradientX) / (float)gradientWidth;
percent = Math.max(percent, percentages.get(dragIndex - 1) + 0.01f);
percent = Math.min(percent, percentages.get(dragIndex + 1) - 0.01f);
percentages.set(dragIndex, percent);
repaint();
}
});
代码示例来源:origin: stanfordnlp/CoreNLP
public static void main(String [] argv) throws Exception {
if (argv.length != 1) {
log.info("Usage: java AceDomReader <APF file>");
System.exit(1);
}
File f = new File(argv[0]);
AceDocument doc = parseDocument(f);
System.out.println("Processed ACE document:\n" + doc);
ArrayList<ArrayList<AceRelationMention>> r = doc.getAllRelationMentions();
System.out.println("size: " + r.size());
}
}
代码示例来源: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
/**
* Returns exception chain starting from top up to root cause.
*/
public static Throwable[] getExceptionChain(Throwable throwable) {
ArrayList<Throwable> list = new ArrayList<>();
list.add(throwable);
while ((throwable = throwable.getCause()) != null) {
list.add(throwable);
}
Throwable[] result = new Throwable[list.size()];
return list.toArray(result);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsWhichThenSubscribesOnAndDelaysAndThenCompletes() throws InterruptedException {
System.err.println("----------------------------------------------------------------------------------------------");
final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete
final ArrayList<String> results = new ArrayList<String>();
Flowable.unsafeCreate(new Publisher<Integer>() {
System.out.println("Results: " + results);
assertEquals(6, results.size());
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testStart() {
Observable<String> os = OBSERVABLE_OF_5_INTEGERS
.zipWith(OBSERVABLE_OF_5_INTEGERS, new BiFunction<Integer, Integer, String>() {
@Override
public String apply(Integer a, Integer b) {
return a + "-" + b;
}
});
final ArrayList<String> list = new ArrayList<String>();
os.subscribe(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
list.add(s);
}
});
assertEquals(5, list.size());
assertEquals("1-1", list.get(0));
assertEquals("2-2", list.get(1));
assertEquals("5-5", list.get(4));
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Adds a list/map reference.
*/
@Override
public int addRef(Object ref) {
if (_refs == null)
_refs = new ArrayList();
_refs.add(ref);
return _refs.size() - 1;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testStartEmptyObservables() {
Observable<String> o = Observable.zip(Observable.<Integer> empty(), Observable.<String> empty(), new BiFunction<Integer, String, String>() {
@Override
public String apply(Integer t1, String t2) {
return t1 + "-" + t2;
}
});
final ArrayList<String> list = new ArrayList<String>();
o.subscribe(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
list.add(s);
}
});
assertEquals(0, list.size());
}
内容来源于网络,如有侵权,请联系作者删除!