I want to convert List<String> to List<Object>.
One of the existing methods is returning List<String> and I want to convert it to List<Object>.
Is there a direct way in Java other then iterating over and converting element by element?
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.
Pass the
List<String>as a parameter to the constructor of a newArrayList<Object>.Any
Collectioncan be passed as an argument to the constructor as long as its type extends the type of theArrayList, asStringextendsObject. The constructor takes aCollection, butListis a subinterface ofCollection, so you can just use theList<String>.