I have a Person class
public class Person
{
private int age;
private String first;
private boolean valid;
}
I have created an ArrayList of Person objects
ArrayList<Person> valid = new ArrayList<Person>();
for(Person p : in)
{
valid.add(p);
}
Now I want to convert this ArrayList to an array; I have tried this:
Person[] people = (Person[]) valid.toArray();
but this is throwing exception
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lcom.net.Person;