开发者

Java Arrays - What are they

开发者_运维百科From looking at the Java Collections API i see that arrays are not regarded as collections. If not what are arrays regarded as?


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.asList which wraps an array with the List<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[] implements IList<T> etc.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜