From looking at the Java Collections API i see that arrays are not regarded as collections.
If not what are arrays regarded as?
From looking at the Java Collections API i see that arrays are not regarded
Share
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.
Arrays are “special” in Java – they don’t implement any interfaces, which means they can’t implement the collection interfaces. They’re collections in “natural language” terms, and you can use the enhanced for loop over them – but if you want to use an array within the collection API, you’ll need something like
Arrays.asListwhich wraps an array with theList<T>interface. (The result is only a view on the array – changes to the array are visible through the list, and vice versa.)(This is in contrast to .NET, where
T[]implementsIList<T>etc.)