当前位置:网站首页>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);
}
}
}
边栏推荐
- How to implement common frameworks
- 3D人脸重建:从基础知识到识别/重建方法!
- Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
- Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
- El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
- ROS error: could not find a package configuration file provided by "move_base“
- SDL2来源分析7:演出(SDL_RenderPresent())
- @PathVariable
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
- JS get array subscript through array content
猜你喜欢

Summary of cross partition scheme

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

【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug

3D人脸重建:从基础知识到识别/重建方法!

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

Deployment of external server area and dual machine hot standby of firewall Foundation

Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software

Is this the feeling of being spoiled by bytes?

ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer

Common English vocabulary that every programmer must master (recommended Collection)
随机推荐
3D人脸重建:从基础知识到识别/重建方法!
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
PG basics -- Logical Structure Management (transaction)
在最长的距离二叉树结点
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Aiko ai Frontier promotion (7.6)
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
通过数字电视通过宽带网络取代互联网电视机顶盒应用
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
Math symbols in lists
Why does MySQL index fail? When do I use indexes?
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
[MySQL] trigger
Absolute primes (C language)
Pat 1078 hashing (25 points) ⼆ times ⽅ exploration method
分糖果
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
每个程序员必须掌握的常用英语词汇(建议收藏)
Quick access to video links at station B
ROS error: could not find a package configuration file provided by "move_base“