当前位置:网站首页>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);
}
}
}
边栏推荐
- Common English vocabulary that every programmer must master (recommended Collection)
- PHP saves session data to MySQL database
- Acdreamoj1110 (multiple backpacks)
- JPEG2000-Matlab源码实现
- 愛可可AI前沿推介(7.6)
- Start the embedded room: system startup with limited resources
- 50个常用的Numpy函数解释,参数和使用示例
- El table table - sortable sorting & disordered sorting when decimal and% appear
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- SQL:存储过程和触发器~笔记
猜你喜欢

Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)

基于深度学习的参考帧生成

Fastjson parses JSON strings (deserialized to list, map)

jvm:大对象在老年代的分配

OneNote 深度评测:使用资源、插件、模版

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

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

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

Reference frame generation based on deep learning

Caching strategies overview
随机推荐
Forward maximum matching method
[interpretation of the paper] machine learning technology for Cataract Classification / classification
R语言做文本挖掘 Part4文本分类
互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地
WEB功能测试说明
js中,字符串和数组互转(一)——字符串转为数组的方法
R language for text mining Part4 text classification
JS learning notes OO create suspicious objects
Binary tree node at the longest distance
js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
Redistemplate common collection instructions opsforlist (III)
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
[MySQL] basic use of cursor
In JS, string and array are converted to each other (II) -- the method of converting array into string
Is this the feeling of being spoiled by bytes?
Summary of cross partition scheme
Torch Cookbook
基于深度学习的参考帧生成
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求