这些方法返回Backed Collection,因为一个Collection中的更改会影响另一个Collection.[写入过程的种类]
Run Code Online (Sandbox Code Playgroud)headSet(e, b) Returns a subset ending at element e and exclusive of e headMap(k, b) Returns a submap ending at key k and exclusive of key k tailSet(e, b) Returns a subset starting at and inclusive of element e tailMap(k, b) Returns a submap starting at and inclusive of key k subSet(s, b, e, b) Returns a subset starting at element s and ending just before element e subMap(s, b, e, b) Returns a submap starting at key s and ending just before key e
那Arrays.asList()方法有什么区别?该方法将数组复制到List中.API表示"对返回列表的更改'通过'向数组写入,反之亦然".
那么,它是否也是一个支持集合?如果是,那么List接口中的toArray()方法 - 是否也是一个支持集合?
有没有其他方法Arrays.asList()允许写入?如何才能通过查看方法签名来了解该方法是否允许写入?
是的,Arrays.asList返回由数组支持的列表,因为它不会复制,而是Collection.toArray复制,因此它不受集合支持.
您无法判断方法是仅从签名中返回由其输入支持的集合 - 仅来自文档.通常,它使用"支持","视图"等词语进行记录.有很多例子 - List.subList例如,Collections.newSetFromMap还有更多例子 - 以及第三方库中的无数例子.
| 归档时间: |
|
| 查看次数: |
5775 次 |
| 最近记录: |