当前位置:网站首页>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);
}
}
}
边栏推荐
- Nodejs tutorial let's create your first expressjs application with typescript
- 【滑动窗口】第九届蓝桥杯省赛B组:日志统计
- Aiko ai Frontier promotion (7.6)
- 红杉中国,刚刚募资90亿美元
- Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
- 代理和反向代理
- [Li Kou brush questions] 32 Longest valid bracket
- VIM basic configuration and frequently used commands
- js中,字符串和数组互转(二)——数组转为字符串的方法
- 中国白酒的5场大战
猜你喜欢

Aiko ai Frontier promotion (7.6)

Seven original sins of embedded development

Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces

缓存更新策略概览(Caching Strategies Overview)

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
![[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs](/img/66/4d94ae24e99599891636013ed734c5.png)
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

【力扣刷题】32. 最长有效括号

Introduction to the use of SAP Fiori application index tool and SAP Fiori tools

Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
随机推荐
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
Binary tree node at the longest distance
在最长的距离二叉树结点
Nodejs tutorial let's create your first expressjs application with typescript
js之遍历数组、字符串
Web开发小妙招:巧用ThreadLocal规避层层传值
Word bag model and TF-IDF
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
This year, Jianzhi Tencent
Yuan Xiaolin: safety is not only a standard, but also Volvo's unchanging belief and pursuit
Common English vocabulary that every programmer must master (recommended Collection)
966 minimum path sum
@PathVariable
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
WEB功能测试说明
OneNote in-depth evaluation: using resources, plug-ins, templates
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
20220211 failure - maximum amount of data supported by mongodb
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software