有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

什么是Java中的备份集合?

这些方法返回已备份的集合,因为一个集合中的更改会影响另一个集合。[一种写通过程]

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()方法有什么区别呢?该方法将数组复制到列表中。API表示“对返回列表的更改‘写入’到阵列,反之亦然”

那么,它是不是太受支持了?如果是,则列表接口中有toArray()方法——这也是一个备份集合吗

是否有其他类似Arrays.asList()的方法允许直写?如何通过查看方法签名来确定该方法是否允许直写


共 (1) 个答案

  1. # 1 楼答案

    是,Arrays.asList返回数组支持的列表,因为它不生成副本,但Collection.toArray生成副本,因此它不受集合支持

    您无法判断方法是否仅从文档中的签名返回由其输入支持的集合。通常,它是用“backby”、“view”之类的词来记录的。有许多例子List.subList,例如Collections.newSetFromMap,第三方库中有更多的例子,还有无数的例子