当前位置:网站首页>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());
}
}
}
边栏推荐
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- It's not my boast. You haven't used this fairy idea plug-in!
- Three schemes of SVM to realize multi classification
- js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
- Thinking about agile development
- The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
- Is this the feeling of being spoiled by bytes?
- Comparison between multithreaded CAS and synchronized
- Study notes of grain Mall - phase I: Project Introduction
- 麦趣尔砸了小众奶招牌
猜你喜欢

This year, Jianzhi Tencent

Summary of cross partition scheme

【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)

Seven original sins of embedded development

3D face reconstruction: from basic knowledge to recognition / reconstruction methods!

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

MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
![[MySQL] trigger](/img/b5/6df17eb254bbdb0aba422d08f13046.png)
[MySQL] trigger

3D人脸重建:从基础知识到识别/重建方法!
![[Li Kou brush questions] 32 Longest valid bracket](/img/51/1ce4f9e8517dba214ec82b6567c923.png)
[Li Kou brush questions] 32 Longest valid bracket
随机推荐
跨分片方案 总结
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
JS操作dom元素(一)——获取DOM节点的六种方式
How do I remove duplicates from the list- How to remove duplicates from a list?
爱可可AI前沿推介(7.6)
Caching strategies overview
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
In JS, string and array are converted to each other (I) -- the method of converting string into array
El table table - sortable sorting & disordered sorting when decimal and% appear
OneNote in-depth evaluation: using resources, plug-ins, templates
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
MySQL - 事务(Transaction)详解
技术分享 | 抓包分析 TCP 协议
Reference frame generation based on deep learning
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
968 edit distance
document. Usage of write () - write text - modify style and position control
R3live notes: image processing section
Study notes of grain Mall - phase I: Project Introduction