这些方法返回Backed Collection,因为一个Collection中的更改会影响另一个Collection。[写入过程的种类]
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()
允许直写?如何才能通过查看方法签名来确定方法是否允许写入?
答案 0 :(得分:8)
是的,Arrays.asList
返回一个由数组支持的列表,因为它没有复制,但Collection.toArray
复制,因此它不受集合支持。
您无法判断方法是仅从签名中返回由其输入支持的集合 - 仅来自文档。通常,它使用“支持”,“视图”等词语进行记录。有许多示例 - List.subList
,例如Collections.newSetFromMap
等等 - 以及第三方库中的无数示例。