当前位置:网站首页>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);
}
}
}
边栏推荐
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
- 967- letter combination of telephone number
- 在最长的距离二叉树结点
- 中国白酒的5场大战
- VIM basic configuration and frequently used commands
- Summary of cross partition scheme
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- Torch Cookbook
- Nodejs教程之让我们用 typescript 创建你的第一个 expressjs 应用程序
- JS操作dom元素(一)——获取DOM节点的六种方式
猜你喜欢

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

【力扣刷题】32. 最长有效括号
![[MySQL] trigger](/img/b5/6df17eb254bbdb0aba422d08f13046.png)
[MySQL] trigger

Caching strategies overview

愛可可AI前沿推介(7.6)

OneNote in-depth evaluation: using resources, plug-ins, templates

Set up a time server

爱可可AI前沿推介(7.6)

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

抖音将推独立种草App“可颂”,字节忘不掉小红书?
随机推荐
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
Ravendb starts -- document metadata
Swagger UI tutorial API document artifact
分糖果
Nodejs教程之Expressjs一篇文章快速入门
通过数字电视通过宽带网络取代互联网电视机顶盒应用
Thinking about agile development
Opencv learning example code 3.2.3 image binarization
968 edit distance
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)
WEB功能测试说明
The biggest pain point of traffic management - the resource utilization rate cannot go up
Three schemes of SVM to realize multi classification
document.write()的用法-写入文本——修改样式、位置控制
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
Hill | insert sort
guava:创建immutableXxx对象的3种方式
Word bag model and TF-IDF
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
El table table - sortable sorting & disordered sorting when decimal and% appear