当前位置:网站首页>guava:Collections.unmodifiableXXX创建的collection并不immutable
guava:Collections.unmodifiableXXX创建的collection并不immutable
2022-07-06 13:10:00 【amadeus_liu2】
一、示例
package com.example.app;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class ImmutableTest {
public static void main(String[] args) {
List<String> stringList=new LinkedList<>();
stringList.add("abc");
stringList.add("def");
List<String> stringList1 = Collections.unmodifiableList(stringList);
stringList.remove(0);
System.out.println(stringList1);
}
}
运行程序输出:
不能通过Collections.unmodifiableXXX创建的引用修改对象,但因原始的stringList是可以修改的,而stringList1和stringList指向同一个对象,stringList修改必然会使stringList1发生变化。
边栏推荐
- Interviewer: what is the internal implementation of ordered collection in redis?
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
- KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
- Ravendb starts -- document metadata
- Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
- 3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
- [Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
- 【力扣刷题】32. 最长有效括号
猜你喜欢

It's not my boast. You haven't used this fairy idea plug-in!

Is it profitable to host an Olympic Games?

缓存更新策略概览(Caching Strategies Overview)

爱可可AI前沿推介(7.6)

Aiko ai Frontier promotion (7.6)

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

面试官:Redis中有序集合的内部实现方式是什么?

None of the strongest kings in the monitoring industry!
![[interpretation of the paper] machine learning technology for Cataract Classification / classification](/img/0c/b76e59f092c1b534736132faa76de5.png)
[interpretation of the paper] machine learning technology for Cataract Classification / classification

OneNote in-depth evaluation: using resources, plug-ins, templates
随机推荐
[Li Kou brush questions] 32 Longest valid bracket
Study notes of grain Mall - phase I: Project Introduction
[interpretation of the paper] machine learning technology for Cataract Classification / classification
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
This year, Jianzhi Tencent
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
JS get array subscript through array content
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
R语言做文本挖掘 Part4文本分类
el-table表格——sortable排序 & 出现小数、%时排序错乱
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
string的底层实现
@PathVariable
Nodejs教程之Expressjs一篇文章快速入门
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
js之遍历数组、字符串
Hill | insert sort
Three schemes of SVM to realize multi classification
Deployment of external server area and dual machine hot standby of firewall Foundation
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.