List has the method add(int, E), so you can use:

list.add(0, yourObject);

Afterwards you can delete the last element with:

if(list.size() > 10)
    list.remove(list.size() - 1);

However, you might want to rethink your requirements or use a different data structure, like a Queue

EDIT

Maybe have a look at Apache's CircularFifoQueue:

CircularFifoQueue is a first-in first-out queue with a fixed size that replaces its oldest element if full.

Just initialize it with you maximum size:

CircularFifoQueue queue = new CircularFifoQueue(10);
Answer from Baz on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
July 21, 2026 - The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation. Each ArrayList instance has a capacity.
🌐
W3Schools
w3schools.com › java › ref_arraylist_add.asp
Java ArrayList add() Method
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> cars = new ArrayList<String>(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); System.out.println(cars); } }
Discussions

arrays - Java ArrayList how to add elements at the beginning - Stack Overflow
I need to add elements to an ArrayList queue whatever, but when I call the function to add an element, I want it to add the element at the beginning of the array (so it has the lowest index) and if... More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to add elements to an Array List all at once?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
6
1
November 2, 2021
java - Adding values to Arraylist - Stack Overflow
Let me just add my favorite not-yet-recognized anti-pattern name here: Mixing unrelated types in a single list smells of object denial. 2012-05-29T10:33:48.69Z+00:00 ... Save this answer. ... Show activity on this post. ... Always specify generic arguments when using generic types (such as ArrayList... More on stackoverflow.com
🌐 stackoverflow.com
java - Add object to ArrayList at specified index - Stack Overflow
I think it's a fairly simple question, but I can't figure out how to do this properly. I've got an empty arraylist: ArrayList list = new ArrayList (); I've got some obje... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-arraylist-add-method-java
Java ArrayList add() Method with Examples - GeeksforGeeks
March 14, 2026 - The add() method in Java ArrayList is used to insert elements into the list dynamically.
Top answer
1 of 16
433

List has the method add(int, E), so you can use:

list.add(0, yourObject);

Afterwards you can delete the last element with:

if(list.size() > 10)
    list.remove(list.size() - 1);

However, you might want to rethink your requirements or use a different data structure, like a Queue

EDIT

Maybe have a look at Apache's CircularFifoQueue:

CircularFifoQueue is a first-in first-out queue with a fixed size that replaces its oldest element if full.

Just initialize it with you maximum size:

CircularFifoQueue queue = new CircularFifoQueue(10);
2 of 16
42

Using Specific Datastructures

There are various data structures which are optimized for adding elements at the first index. Mind though, that if you convert your collection to one of these, the conversation will probably need a time and space complexity of O(n)

Deque

The JDK includes the Deque structure which offers methods like addFirst(e) and offerFirst(e)

Deque<String> deque = new LinkedList<>();
deque.add("two");
deque.add("one");
deque.addFirst("three");
//prints "three", "two", "one"

Analysis

Space and time complexity of insertion is with LinkedList constant (O(1)). See the Big-O cheatsheet.

Reversing the List

A very easy but inefficient method is to use reverse:

 Collections.reverse(list);
 list.add(elementForTop);
 Collections.reverse(list);

If you use Java 8 streams, this answer might interest you.

Analysis

  • Time Complexity: O(n)
  • Space Complexity: O(1)

Looking at the JDK implementation this has a O(n) time complexity so only suitable for very small lists.

🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › ArrayList.html
ArrayList (Java SE 21 & JDK 21)
January 20, 2026 - Adds an element as the last element of this collection (optional operation). ... Removes all of the elements from this list. ... Returns a shallow copy of this ArrayList instance.
🌐
Blogger
javahungry.blogspot.com › 2017 › 10 › how-to-add-element-in-arraylist-add-method-example.html
How to add element in ArrayList : add() Method Example | Java Hungry
The method signature of add method is public boolean add(Object element) According to Java docs, ArrayList add() method appends the specified element to the end of the list.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_add_index.htm
Java.util.ArrayList.add() Method
The java.util.ArrayList.add(int index, E elemen) method inserts the specified element E at the specified position in this list.It shifts the element currently at that position (if any) and any subsequent elements to the right (will add one to ...
🌐
Processing Foundation
discourse.processing.org › beginners
Add an Array to an ArrayList - Beginners - Processing Community Forum
January 6, 2020 - I’ve created a REALLY simple code snippet to show what I’m trying to do. I need to add an array that I have defined into an ArrayList. I need an ArrayList as I don’t know how many arrays I will end up with. This will Obvs be in a loop but I just wanted to show the problem I’m having When I run the following float[] stuff = {1,2,3}; ArrayList list = new ArrayList (); list.add(stuff); printArray(list); I am hoping to see 1,2,3 in the first entry for the ArrayList. instead I j...
🌐
CodeHS
codehs.com › tutorial › 13901
Tutorial: ArrayLists in Java | CodeHS
Learn how to create and use ArrayLists in your programs!
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › add
Java ArrayList add() - Add Element | Vultr Docs
November 29, 2024 - Make sure the ArrayList already exists. Use add(int index, E element) to insert an element at a desired index.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-add-method-example
Java ArrayList add() Method Example
September 17, 2022 - The add() method of Java ArrayList class is used to add elements to an ArrayList.
🌐
TutorialsPoint
tutorialspoint.com › article › adding-elements-in-the-middle-of-an-arraylist-in-java
Adding elements in the middle of an ArrayList in Java
July 30, 2019 - Elements can be added in the middle of an ArrayList by using the java.util.ArrayList.add() method. This method has two parameters i.e. the index at which to insert the element in the ArrayList and the element itself.
🌐
Coderanch
coderanch.com › t › 549828 › java › ArrayList-add-method
ArrayList add() method (Java in General forum at Coderanch)
August 19, 2011 - ArrayList list=new ArrayList(); ArrayList<String> listStr=list; ArrayList<StringBuffer> listBuf=list; list.add(0,"ListHello"); System.out.println(list); System.out.println(listStr); System.out.println(listBuf); The String object ListHello gets added to list,listStr and listBuf, though I am adding the object to listStr, how is it getting added to list and listBuf can anyone explain the reason
🌐
Codecademy
codecademy.com › docs › java › arraylist › .add()
Java | ArrayList | .add() | Codecademy
March 21, 2022 - The .add() method is used for adding elements to instances of the ArrayList class.
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_add.htm
Java ArrayList add() Method
The Java ArrayList add(int index, E element) method inserts the specified element E at the specified position in this list.It shifts the element currently at that position (if any) and any subsequent elements to the right (will add one to their ...