当前位置:网站首页>Guava: use of multiset
Guava: use of multiset
2022-07-06 21:30:00 【amadeus_ liu2】
package com.example.app;
import com.google.common.collect.*;
import java.util.Iterator;
public class MultiSetTest {
public static void main(String[] args) {
Multiset<String> multiSet = HashMultiset.create();
//Multiset There will be duplicate elements in , Like the following "abc"
multiSet.add("abc");
multiSet.add("abc");
multiSet.add("def");
// When adding elements, you can directly specify the number of repetitions of an element
multiSet.add("ghi",4);
// You can remove a specified element by the number of times
multiSet.remove("ghi",1);
// You can directly set the number of specified elements
multiSet.setCount("ghi",5);
// Set the number of elements to 0, It is equivalent to deleting the element
multiSet.setCount("def",0);
//size() Method will return the number of all elements , Contains duplicate elements
System.out.println(multiSet.size());
// Returns the number of repetitions of an element
System.out.println(multiSet.count("abc"));
// Return similar map Of EntrySet
System.out.println(multiSet.entrySet());
// Return all elements without repetition
System.out.println(multiSet.elementSet());
System.out.println("________________________________________________________________");
// Acquisition iterator , Traverse
Iterator<String> iterator = multiSet.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
}
边栏推荐
- Aiko ai Frontier promotion (7.6)
- It's almost the new year, and my heart is lazy
- Why does MySQL index fail? When do I use indexes?
- In JS, string and array are converted to each other (I) -- the method of converting string into array
- Proxy and reverse proxy
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- Redistemplate common collection instructions opsforhash (IV)
- 038. (2.7) less anxiety
- 基于深度学习的参考帧生成
- Set up a time server
猜你喜欢
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
None of the strongest kings in the monitoring industry!
Data Lake (VIII): Iceberg data storage format
缓存更新策略概览(Caching Strategies Overview)
Deployment of external server area and dual machine hot standby of firewall Foundation
20220211 failure - maximum amount of data supported by mongodb
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
麦趣尔砸了小众奶招牌
随机推荐
Ravendb starts -- document metadata
Redistemplate common collection instructions opsforset (V)
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
首批入选!腾讯安全天御风控获信通院业务安全能力认证
R语言做文本挖掘 Part4文本分类
VIM basic configuration and frequently used commands
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
el-table表格——sortable排序 & 出现小数、%时排序错乱
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
b站视频链接快速获取
El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
Study notes of grain Mall - phase I: Project Introduction
Word bag model and TF-IDF
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
[go][reprint]vscode run a HelloWorld example after configuring go
Three schemes of SVM to realize multi classification
ICML 2022 | flowformer: task generic linear complexity transformer
[MySQL] trigger
Nodejs tutorial expressjs article quick start
14 years Bachelor degree, transferred to software testing, salary 13.5k