Skip to content
Sign upLog in
← Back to Community
i not get how add item into array list
Profile icon
studentSakethSa

i not get how add item into array list

Voters
Profile icon
gustavointriago
Comments
hotnewtop
Profile icon
IntellectualGuy

You have 3 errors, first you need to import Arraylist like so

import java.util.ArrayList;

Secondly you need to change the arraylist declaration like so

ArrayList fg = new ArrayList();

Instead of .addFlower, you need .add like so

fg.add("daisy");

After this it should work


If it doesn't please reply and tell me the problem
Hope it helps :)

Profile icon
studentSakethSa

ds

Profile icon
RYANTADIPARTHI

@studentSakethSa
ok, np. click check mark please.

Profile icon
RYANTADIPARTHI

Solution

use the add() method to perform this task. Try this code.

import java.util.*; public class GfG { public static void main(String[] args) { List<Integer> l = new ArrayList<>(); l.add(10); l.add(15); l.add(20); System.out.println(l); } }

like that.
That should work

here's a link for more info.

https://www.geeksforgeeks.org/list-add-method-in-java-with-examples/