Master Przemo
Master Przemo

Reputation: 35

Passing argument to java's constructor method of type List

I have constructor method that looks like the following:

public Profile(List<PointGrade> g)

If i want to call that method in different class, how do I pass argument of type list?

Upvotes: 0

Views: 52

Answers (4)

Abdelhak
Abdelhak

Reputation: 8387

You should create an istance of the object Profile like this:

  List<PointGrade> list = new ArrayList<PointGrade>();
  Profile profile =new Profile(list);

And you can use this istance maybe like this:

     profile.someMethod();

Upvotes: 1

Keammoort
Keammoort

Reputation: 3075

Create an instance of List:

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

Populate it with some data (if you don't want to pass empty list):

PointGrade pg = new PointGrade();

//fill PointGrade fields you need

list.add(pg);

And then pass it to a constructor:

Profile profile = new Profile(list);

Upvotes: 0

Vitali
Vitali

Reputation: 549

Profile profile = new Profile(new List<PointGrade>());

Upvotes: 0

List< PointGrade> g=new ArrayList< PointGrade>();

XXX.Profile(g);

Upvotes: 0

Related Questions