当前位置:网站首页>guava:创建immutableXxx对象的3种方式
guava:创建immutableXxx对象的3种方式
2022-07-06 13:10:00 【amadeus_liu2】
可以通过of copyOf 和builder 三种方式创建不可变对象
package com.example.app;
import com.google.common.collect.ImmutableSet;
import java.util.HashSet;
import java.util.Set;
public class ImmutableTest2 {
public static void main(String[] args) {
Set<String> originalSet=new HashSet<>();
originalSet.add("abc");
originalSet.add("def");
originalSet.add("ghi");
ImmutableSet<String> immutableSet = ImmutableSet.copyOf(originalSet);
for(String str: immutableSet){
System.out.println(str);
}
System.out.println("______________________________________________________");
ImmutableSet<String> immutableSet1 = ImmutableSet.of("abc","def","ghi");
for(String str: immutableSet1){
System.out.println(str);
}
System.out.println("______________________________________________________");
ImmutableSet<String> immutableSet2 = ImmutableSet.<String>builder()
.add("abc")
.add("def")
.add("ghi")
.build();
for(String str: immutableSet2){
System.out.println(str);
}
}
}
边栏推荐
- js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
- 3D人脸重建:从基础知识到识别/重建方法!
- How do I remove duplicates from the list- How to remove duplicates from a list?
- KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
- R language for text mining Part4 text classification
- OneNote 深度评测:使用资源、插件、模版
- Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
- JS操作dom元素(一)——获取DOM节点的六种方式
- 【论文解读】用于白内障分级/分类的机器学习技术
- Hill | insert sort
猜你喜欢
Seven original sins of embedded development
Why do job hopping take more than promotion?
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
缓存更新策略概览(Caching Strategies Overview)
None of the strongest kings in the monitoring industry!
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
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
PHP saves session data to MySQL database
随机推荐
Technology sharing | packet capturing analysis TCP protocol
愛可可AI前沿推介(7.6)
Yyds dry inventory run kubeedge official example_ Counter demo counter
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
Comparison between multithreaded CAS and synchronized
【mysql】触发器
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
The biggest pain point of traffic management - the resource utilization rate cannot go up
JS get array subscript through array content
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
JS traversal array and string
Fzu 1686 dragon mystery repeated coverage
3D人脸重建:从基础知识到识别/重建方法!
Data Lake (VIII): Iceberg data storage format
基于深度学习的参考帧生成
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅