AP® Computer Science A glossary

ArrayList methods

Course: AP® Computer Science A Shows up in: Unit 4: Data Collections

The Java Quick Reference ArrayList methods: size, add(obj), add(index, obj), get, set and remove; add and remove at an index shift later elements.

Appears in the course and exam description (CED): 4.8.A.5

add(index, obj) moves later elements right (size + 1); remove(index) moves them left (size - 1) and returns the removed element; set returns the element it replaced.

ArrayList<String> q = new ArrayList<String>();
q.add("A");
q.add("C");
q.add(1, "B");
String old = q.set(2, "D");
System.out.println(q + " " + old);
String gone = q.remove(0);
System.out.println(gone + " " + q);

Output:

[A, B, D] C
A [B, D]
Learn it properly, with a checkpoint 4.8 ArrayList Methods

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure