P.Ambh P.Ambh - 9 months ago 49
Java Question

How to populate a collection in java?

Suppose we are creating a class in java where name and code are two private members and then are passing them in the list.

class A
private int code;
private string name;
public getCode()
{ return code;}
public setCode(int code){this.code=code;}
public getName()
{ return name;}
public setName(String name){this.name=name;}

class B {
List<A> l1=new List<A>

Now how to populate list A?

A obj = new A();

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