Is there a way to use the toArray() method on an ArrayList<CustomObject>?
From what I see, it can only be used with Object
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to pass in an array of
CustomObjectin order to get one back. The parameter-freeArrayList.toArray()call returns anObject[], but the parameterized versionT[] ArrayList<T>.toArray(T[])returns what you expect. If you size the array you pass as a parameter correctly then the call will use the array you pass rather than allocate another one, e.g.