当前位置:网站首页>Guava: three ways to create immutablexxx objects
Guava: three ways to create immutablexxx objects
2022-07-06 21:33:00 【amadeus_ liu2】
Can pass of copyOf and builder There are three ways to create immutable objects
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);
}
}
}
边栏推荐
- Quick access to video links at station B
- Nodejs tutorial let's create your first expressjs application with typescript
- KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
- 启动嵌入式间:资源有限的系统启动
- 968 edit distance
- None of the strongest kings in the monitoring industry!
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
- [in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
- 50个常用的Numpy函数解释,参数和使用示例
- [MySQL] basic use of cursor
猜你喜欢
跨分片方案 总结
Set up a time server
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
Summary of cross partition scheme
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
50个常用的Numpy函数解释,参数和使用示例
The biggest pain point of traffic management - the resource utilization rate cannot go up
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
20220211 failure - maximum amount of data supported by mongodb
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
随机推荐
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
OSPF multi zone configuration
[go][转载]vscode配置完go跑个helloworld例子
[Li Kou brush questions] 32 Longest valid bracket
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
In JS, string and array are converted to each other (II) -- the method of converting array into string
PHP saves session data to MySQL database
jvm:大对象在老年代的分配
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
在最长的距离二叉树结点
通过数字电视通过宽带网络取代互联网电视机顶盒应用
R3live notes: image processing section
JS操作dom元素(一)——获取DOM节点的六种方式
Is it profitable to host an Olympic Games?
嵌入式开发的7大原罪
This year, Jianzhi Tencent
3D人脸重建:从基础知识到识别/重建方法!