当前位置:网站首页>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());
}
}
}
边栏推荐
- 监控界的最强王者,没有之一!
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Notes - detailed steps of training, testing and verification of yolo-v4-tiny source code
- R3live notes: image processing section
- Three schemes of SVM to realize multi classification
- 【论文解读】用于白内障分级/分类的机器学习技术
- How to implement common frameworks
- [redis design and implementation] part I: summary of redis data structure and objects
- 【mysql】触发器
猜你喜欢

Fastjson parses JSON strings (deserialized to list, map)

After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers

966 minimum path sum

968 edit distance

Aiko ai Frontier promotion (7.6)

互联网快讯:吉利正式收购魅族;胰岛素集采在31省全面落地

967- letter combination of telephone number

Z function (extended KMP)

20220211 failure - maximum amount of data supported by mongodb

Why do job hopping take more than promotion?
随机推荐
js中,字符串和数组互转(一)——字符串转为数组的方法
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
ROS error: could not find a package configuration file provided by "move_base“
Forward maximum matching method
Nodejs tutorial let's create your first expressjs application with typescript
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
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
Fastjson parses JSON strings (deserialized to list, map)
Study notes of grain Mall - phase I: Project Introduction
[MySQL] trigger
It's almost the new year, and my heart is lazy
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
JS操作dom元素(一)——获取DOM节点的六种方式
[interpretation of the paper] machine learning technology for Cataract Classification / classification
In JS, string and array are converted to each other (I) -- the method of converting string into array
Acdreamoj1110 (multiple backpacks)
每个程序员必须掌握的常用英语词汇(建议收藏)
跨分片方案 总结