First simple rule: never use the String(String) constructor, it is absolutely useless (*).

So arr.add("ss") is just fine.

With 3 it's slightly different: 3 is an int literal, which is not an object. Only objects can be put into a List. So the int will need to be converted into an Integer object. In most cases that will be done automagically for you (that process is called autoboxing). It effectively does the same thing as Integer.valueOf(3) which can (and will) avoid creating a new Integer instance in some cases.

So actually writing arr.add(3) is usually a better idea than using arr.add(new Integer(3)), because it can avoid creating a new Integer object and instead reuse and existing one.

Disclaimer: I am focusing on the difference between the second and third code blocks here and pretty much ignoring the generics part. For more information on the generics, please check out the other answers.

(*) there are some obscure corner cases where it is useful, but once you approach those you'll know never to take absolute statements as absolutes ;-)

Answer from Joachim Sauer on Stack Overflow
🌐
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).
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-arraylist-add-method-java
Java ArrayList add() Method with Examples - GeeksforGeeks
March 14, 2026 - ... Exception: Throws ... an empty ArrayList ArrayList<Integer> al = new ArrayList<>(); // Use add() method to // add elements in the list al.add(10); al.add(20); al.add(30); al.add(40); System.out.println("" + ...
Discussions

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
Automatically create new objects in Java with ArrayList?
ArrayLists grow as needed. You only can (but don't need to) set the initial capacity. You just .add a new element to the ArrayList. Java takes care of the rest. https://www.baeldung.com/java-arraylist More on reddit.com
🌐 r/learnprogramming
6
1
May 14, 2021
Adding to an ArrayList Java - Stack Overflow
I am a beginner to java, and need some help. I am trying to convert an Abstract Data type Foo which is an associated list to an Arraylist of the strings B. How do you loop through the list and add each string to the array. I may be over thinking it, but I am lost now. Thanks for the help in advance. ... Iterate over your data structure (with a for loop, for instance, more details on your code would help.) and for each element ... More on stackoverflow.com
🌐 stackoverflow.com
Add an object to an ArrayList on another class
Classname.ArrayListname.add(objectname) basically just do it normal but add the class name and . , as long as the arraylist is a public field More on reddit.com
🌐 r/javahelp
4
5
December 8, 2019
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
April 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 ... cars.add("Ford"); cars.add("Mazda"); System.out.println(cars); } } ... The add() method adds an item to the list....
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java ArrayList Insert/Replace At Index - Java Code Geeks
January 2, 2022 - Use the ArrayList.add(int index, Object value) method to add any object or element at the specific index of ArrayList and use ArrayList.set(int index, E value) to replace the value at the specific index of ArrayList in java.
Find elsewhere
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › add
Java ArrayList add() - Add Element | Vultr Docs
November 29, 2024 - The add() method in Java's ArrayList class is one of the most frequently used operations for dynamically managing collections of objects. This method allows for the insertion of elements into an ArrayList, providing flexibility and ease of use ...
🌐
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.
🌐
Reddit
reddit.com › r/learnprogramming › automatically create new objects in java with arraylist?
r/learnprogramming on Reddit: Automatically create new objects in Java with ArrayList?
May 14, 2021 -

Hello everyone.

I'm trying to make a bank program and I'm planning how to implement adding a new customer. I know ArrayLists and I wanted to make it as a list of objects but it seems like I still have to have a set size in order to assign a new account to a new object? Is there a way that once the user chooses to make a new account, a customer object is automatically created?

sorry if I'm not clear I'm still a bit new to programming.

🌐
Oracle
docs.oracle.com › en › java › javase › 20 › docs › api › java.base › java › util › ArrayList.html
ArrayList (Java SE 20 & JDK 20)
July 10, 2023 - 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.
🌐
Programiz
programiz.com › java-programming › library › arraylist › add
Java ArrayList add()
Java ArrayList ensureCapacity() The add() method inserts an element to the arraylist at the specified position. import java.util.ArrayList; class Main { public static void main(String[] args) { // create an ArrayList ArrayList<String> languages = new ArrayList<>(); // insert element to the ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-in-java
ArrayList in Java - GeeksforGeeks
Explanation: This program creates an ArrayList of integers, adds elements to it using the add() method, and stores them dynamically.
Published   May 12, 2026
🌐
Sarthaks eConnect
sarthaks.com › 3492993 › how-do-i-add-elements-to-an-arraylist-in-java
How do I add elements to an ArrayList in Java? - Sarthaks eConnect | Largest Online Education Community
April 25, 2023 - LIVE Course for free · To add elements to an ArrayList in Java, you can use the add() method provided by the ArrayList class. Here's an example code snippet to add elements to an ArrayList:
🌐
Medium
harsh05.medium.com › mastering-collections-in-java-why-and-how-to-use-arraylist-98bb8cb202ca
Mastering Collections in Java: Why and How to Use ArrayList | by @Harsh | Medium
October 13, 2024 - In this blog, we’ll explore why collections are necessary, the limitations of arrays, and how ArrayList, one of the key implementations of the Java Collection Framework, overcomes these issues. ... Before diving into collections, let’s start by looking at how data was managed in Java using arrays. Arrays are one of the most basic data structures in Java, allowing us to store a fixed number of elements of the same type.
🌐
PREP INSTA
prepinsta.com › home › java tutorial › java arraylist add() function
ArrayList add Function in Java || PrepInsta
February 14, 2023 - We can also insert an element in the existing arraylist by specifying the location of the element in the add() function. ... // Importing all the required packages import java.util.*; public class Main{ public static void main(String[] args) ...
🌐
Java Development Journal
javadevjournal.com › home › arraylist add method example
ArrayList add Method Example | Java Development Journal
August 26, 2021 - Le’s inspect the different example of adding element to the ArrayList and the different overloaded variations. The default method (used in most cases) add(100) will add the element to the end of the list.
🌐
Codekru
codekru.com › home › arraylist add() method in java
ArrayList add() method in Java - Codekru
August 12, 2022 - Remember, the indexing here starts from 0, so if you want to add the element at the 3rd position, you must pass the index as 2 into the function. What does it return? – It does not return anything as the function’s return type is void. public class Codekru { public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); // appending the elements at the end of the list al.add("First"); al.add("Third"); // inserting the element at 2nd postion, by passing index as 1 al.add(1, "Second"); // printing the contents of the list System.out.println("ArrayList contents: " + al.toString()); } }
🌐
Programiz
programiz.com › java-programming › arraylist
Java ArrayList (With Examples)
In Java, we need to declare the size of an array before we can use it. Once the size of an array is declared, it's hard to change it. To handle this issue, we can use the ArrayList class. It allows us to create resizable arrays. Unlike arrays, arraylists can automatically adjust their capacity when we add or remove elements ...