当前位置:网站首页>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);
}
}
}
边栏推荐
- Is this the feeling of being spoiled by bytes?
- 分糖果
- 审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
- [Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
- Opencv learning example code 3.2.3 image binarization
- PG basics -- Logical Structure Management (transaction)
- 首批入选!腾讯安全天御风控获信通院业务安全能力认证
- [in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
- 每个程序员必须掌握的常用英语词汇(建议收藏)
猜你喜欢
OneNote 深度评测:使用资源、插件、模版
Common English vocabulary that every programmer must master (recommended Collection)
Study notes of grain Mall - phase I: Project Introduction
【mysql】游标的基本使用
【论文解读】用于白内障分级/分类的机器学习技术
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
Opencv learning example code 3.2.3 image binarization
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
随机推荐
Deployment of external server area and dual machine hot standby of firewall Foundation
R language for text mining Part4 text classification
None of the strongest kings in the monitoring industry!
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
document.write()的用法-写入文本——修改样式、位置控制
愛可可AI前沿推介(7.6)
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Binary tree node at the longest distance
@PathVariable
Ravendb starts -- document metadata
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
How to implement common frameworks
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
OSPF multi zone configuration
[interpretation of the paper] machine learning technology for Cataract Classification / classification
Redistemplate common collection instructions opsforset (V)
MySQL - 事务(Transaction)详解
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
【滑动窗口】第九届蓝桥杯省赛B组:日志统计