当前位置:网站首页>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);
}
}
}
边栏推荐
- jvm:大对象在老年代的分配
- Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
- JS operation DOM element (I) -- six ways to obtain DOM nodes
- Proxy and reverse proxy
- [sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
- 基于深度学习的参考帧生成
- JS get array subscript through array content
- MySQL - transaction details
- 3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
- JPEG2000-Matlab源码实现
猜你喜欢
Aiko ai Frontier promotion (7.6)
[MySQL] trigger
Set up a time server
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
3D人脸重建:从基础知识到识别/重建方法!
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
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
Swagger UI tutorial API document artifact
麦趣尔砸了小众奶招牌
随机推荐
ICML 2022 | flowformer: task generic linear complexity transformer
c语言char, wchar_t, char16_t, char32_t和字符集的关系
Acdreamoj1110 (multiple backpacks)
3D人脸重建:从基础知识到识别/重建方法!
JS操作dom元素(一)——获取DOM节点的六种方式
Sdl2 source analysis 7: performance (sdl_renderpresent())
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Start the embedded room: system startup with limited resources
Redistemplate common collection instructions opsforzset (VI)
string的底层实现
ACdreamoj1110(多重背包)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
js中,字符串和数组互转(二)——数组转为字符串的方法
Data Lake (VIII): Iceberg data storage format
Yyds dry inventory run kubeedge official example_ Counter demo counter
JS学习笔记-OO创建怀疑的对象
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)