当前位置:网站首页>guava: Multiset的使用
guava: Multiset的使用
2022-07-06 13:10: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中会存在重复元素,比如下面的"abc"
multiSet.add("abc");
multiSet.add("abc");
multiSet.add("def");
//添加元素时可以直接指定某个元素的重复次数
multiSet.add("ghi",4);
//可以按次数移除某个指定元素
multiSet.remove("ghi",1);
//可以直接设置指定元素的个数
multiSet.setCount("ghi",5);
//将元素个数设置为0,则相当于把该元素删除了
multiSet.setCount("def",0);
//size()方法会返回所有元素的个数,包含重复的元素
System.out.println(multiSet.size());
//返回某个元素的重复次数
System.out.println(multiSet.count("abc"));
//返回类似map的EntrySet
System.out.println(multiSet.entrySet());
//返回不重复的所有元素
System.out.println(multiSet.elementSet());
System.out.println("________________________________________________________________");
//获取迭代器,遍历
Iterator<String> iterator = multiSet.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
}
边栏推荐
- Torch Cookbook
- What's the best way to get TFS to output each project to its own directory?
- Set up a time server
- 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
- It's almost the new year, and my heart is lazy
- Deployment of external server area and dual machine hot standby of firewall Foundation
- Ravendb starts -- document metadata
- None of the strongest kings in the monitoring industry!
- Replace Internet TV set-top box application through digital TV and broadband network
- 967- letter combination of telephone number
猜你喜欢
Summary of cross partition scheme
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
Study notes of grain Mall - phase I: Project Introduction
愛可可AI前沿推介(7.6)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
039. (2.8) thoughts in the ward
Set up a time server
【论文解读】用于白内障分级/分类的机器学习技术
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
随机推荐
None of the strongest kings in the monitoring industry!
'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
Summary of cross partition scheme
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
Manifest of SAP ui5 framework json
In JS, string and array are converted to each other (II) -- the method of converting array into string
Word bag model and TF-IDF
JS operation DOM element (I) -- six ways to obtain DOM nodes
document. Usage of write () - write text - modify style and position control
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Study notes of grain Mall - phase I: Project Introduction
R language for text mining Part4 text classification
Nodejs tutorial expressjs article quick start
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
Absolute primes (C language)
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
js之遍历数组、字符串
SDL2来源分析7:演出(SDL_RenderPresent())
首批入选!腾讯安全天御风控获信通院业务安全能力认证
3D人脸重建:从基础知识到识别/重建方法!