Say I have a Person class and I am trying to create a list as;
Person p1 = new Person("first", "id1");
Person p2 = new Person("dummy", "id1");
Person p3 = new Person("second", "id2");
Person p4 = new Person("third", "id1");
List<Person> asList = Arrays.asList(p1, p2, p3, p4);
Now my question is instead of passing the indivdual Person objects to Arrays.asList()
can I pass a combined list, something like
List<Person> asList = Arrays.asList(combinedPersonObjs);
I have tried many things, but am getting casting errors.
Please help
Note: The number of Person objects is dynamic.
Sure, you can do
If you don’t know the number of
Personobjects in advance, then presumably you don’t have one variable identifier for each object. I suggest you simply do something like