Java List: How to Add Elements

To add elements to a Java list, you can use the add() method. Here is an example code:

List<String> list = new ArrayList<>();

// 添加元素
list.add("元素1");
list.add("元素2");
list.add("元素3");

In the code above, three elements are added to the list using the add() method. After adding the elements, the size of the list will increase automatically.

bannerAds