So, I have a class that creates an ArrayList
of objects, but I have another superior class that is the one that operates with that ArrayList
, so I understand I have to create a new object of that class.
How can I do it? I have done it in a way it doesn't accept the ArrayList
methods (add
, size
...)
Probably this is simple, but I just started Java. like this:
public class Objects {
private List<objects> list = new ArrayList<>
}
-------------------------
public class List {
private Objects list;
public List() {
list= new Objects;
}
It looks like it is not like this, because I cant use add
, get
or size
. I would appreciate some help. And if you are asking, I need the objects class. Thank you.
--------------------------------------- EDIT----------------------------------
I need a method to add an object, but it says add, size and get is not defined. i thought i can use de default ones
public void add (Object pea){
this.list.add(pea);
}
it says it doesnt work