当前位置:网站首页>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教程之Expressjs一篇文章快速入门
- The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
- Redistemplate common collection instructions opsforhash (IV)
- Proxy and reverse proxy
- Nodejs tutorial expressjs article quick start
- Absolute primes (C language)
- Comparison between multithreaded CAS and synchronized
- Hill | insert sort
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
猜你喜欢
嵌入式开发的7大原罪
None of the strongest kings in the monitoring industry!
中国白酒的5场大战
20220211 failure - maximum amount of data supported by mongodb
[Li Kou brush questions] 32 Longest valid bracket
Interviewer: what is the internal implementation of ordered collection in redis?
50个常用的Numpy函数解释,参数和使用示例
The biggest pain point of traffic management - the resource utilization rate cannot go up
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
缓存更新策略概览(Caching Strategies Overview)
随机推荐
Caching strategies overview
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
[go][转载]vscode配置完go跑个helloworld例子
Thinking about agile development
红杉中国,刚刚募资90亿美元
Redistemplate common collection instructions opsforzset (VI)
JS operation DOM element (I) -- six ways to obtain DOM nodes
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
It's almost the new year, and my heart is lazy
技术分享 | 抓包分析 TCP 协议
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Redistemplate common collection instructions opsforhash (IV)
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
Aike AI frontier promotion (7.6)
js中,字符串和数组互转(一)——字符串转为数组的方法
14年本科毕业,转行软件测试,薪资13.5K
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
Is this the feeling of being spoiled by bytes?