当前位置:网站首页>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
- VIM basic configuration and frequently used commands
- Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
- el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
- Is it profitable to host an Olympic Games?
- @Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
- ICML 2022 | flowformer: task generic linear complexity transformer
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- Study notes of grain Mall - phase I: Project Introduction
猜你喜欢
![[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

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

2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性

Is this the feeling of being spoiled by bytes?

Reference frame generation based on deep learning

跨分片方案 总结

KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning

Interviewer: what is the internal implementation of ordered collection in redis?

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

爱可可AI前沿推介(7.6)
随机推荐
C语言:#if、#def和#ifndef综合应用
Redistemplate common collection instructions opsforhash (IV)
Vim 基本配置和经常使用的命令
MySQL - 事务(Transaction)详解
启动嵌入式间:资源有限的系统启动
抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
VIM basic configuration and frequently used commands
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
Redistemplate common collection instructions opsforlist (III)
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
OSPF multi zone configuration
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
跨分片方案 总结
guava: Multiset的使用
It's not my boast. You haven't used this fairy idea plug-in!
Is it profitable to host an Olympic Games?
@GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅