当前位置:网站首页>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发生变化。
边栏推荐
- document. Usage of write () - write text - modify style and position control
- Is it profitable to host an Olympic Games?
- 基于深度学习的参考帧生成
- What's the best way to get TFS to output each project to its own directory?
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
- 袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
- 启动嵌入式间:资源有限的系统启动
- JS traversal array and string
- 通过数字电视通过宽带网络取代互联网电视机顶盒应用
- js中,字符串和数组互转(一)——字符串转为数组的方法
猜你喜欢
数据湖(八):Iceberg数据存储格式
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
缓存更新策略概览(Caching Strategies Overview)
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
3D人脸重建:从基础知识到识别/重建方法!
Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
【mysql】游标的基本使用
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
随机推荐
What's the best way to get TFS to output each project to its own directory?
Why do job hopping take more than promotion?
14年本科毕业,转行软件测试,薪资13.5K
Web开发小妙招:巧用ThreadLocal规避层层传值
VIM basic configuration and frequently used commands
Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
Set up a time server
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
PG basics -- Logical Structure Management (transaction)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
Nodejs tutorial expressjs article quick start
Swagger UI教程 API 文档神器
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
【论文解读】用于白内障分级/分类的机器学习技术
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
967- letter combination of telephone number
Thinking about agile development
Why does MySQL index fail? When do I use indexes?
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序