当前位置:网站首页>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());
}
}
}
边栏推荐
- 968 edit distance
- SDL2来源分析7:演出(SDL_RenderPresent())
- FZU 1686 龙之谜 重复覆盖
- Vim 基本配置和经常使用的命令
- Fastjson parses JSON strings (deserialized to list, map)
- 对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
- 分糖果
- OSPF multi zone configuration
- The biggest pain point of traffic management - the resource utilization rate cannot go up
- 038. (2.7) less anxiety
猜你喜欢
Aiko ai Frontier promotion (7.6)
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
Seven original sins of embedded development
039. (2.8) thoughts in the ward
Common English vocabulary that every programmer must master (recommended Collection)
Why do job hopping take more than promotion?
爱可可AI前沿推介(7.6)
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
[interpretation of the paper] machine learning technology for Cataract Classification / classification
随机推荐
Why do job hopping take more than promotion?
In JS, string and array are converted to each other (II) -- the method of converting array into string
Sdl2 source analysis 7: performance (sdl_renderpresent())
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
jvm:大对象在老年代的分配
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
对话阿里巴巴副总裁贾扬清:追求大模型,并不是一件坏事
Swagger UI tutorial API document artifact
SDL2来源分析7:演出(SDL_RenderPresent())
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
R语言做文本挖掘 Part4文本分类
Deployment of external server area and dual machine hot standby of firewall Foundation
跨分片方案 总结
OneNote 深度评测:使用资源、插件、模版
Fzu 1686 dragon mystery repeated coverage
Interviewer: what is the internal implementation of ordered collection in redis?
What's the best way to get TFS to output each project to its own directory?
JS operation DOM element (I) -- six ways to obtain DOM nodes
968 edit distance