EN
Java - add items to ArrayList
0 points
In this article, we would like to show you how to add items to ArrayList in Java.
Quick solution:
xxxxxxxxxx
1
List<String> fruits = new ArrayList<>();
2
fruits.add("Apple");
In this example, we show how to add items to the fruits
ArrayList using add()
method.
xxxxxxxxxx
1
import java.util.ArrayList;
2
3
public class Example {
4
5
public static void main(String[] args) {
6
List<String> fruits = new ArrayList<>();
7
8
fruits.add("Apple");
9
fruits.add("Banana");
10
fruits.add("Cherry");
11
12
System.out.println(fruits);
13
}
14
}
output:
xxxxxxxxxx
1
[Apple, Banana, Cherry]