当前位置:网站首页>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());
}
}
}
边栏推荐
- Swagger UI tutorial API document artifact
- Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
- 3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
- ICML 2022 | flowformer: task generic linear complexity transformer
- What's the best way to get TFS to output each project to its own directory?
- This year, Jianzhi Tencent
- How do I remove duplicates from the list- How to remove duplicates from a list?
- 968 edit distance
- 14 years Bachelor degree, transferred to software testing, salary 13.5k
- guava:创建immutableXxx对象的3种方式
猜你喜欢
2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history
缓存更新策略概览(Caching Strategies Overview)
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
Seven original sins of embedded development
Summary of cross partition scheme
ICML 2022 | flowformer: task generic linear complexity transformer
The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop
中国白酒的5场大战
抖音将推独立种草App“可颂”,字节忘不掉小红书?
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
随机推荐
document.write()的用法-写入文本——修改样式、位置控制
Sdl2 source analysis 7: performance (sdl_renderpresent())
guava:Collections.unmodifiableXXX创建的collection并不immutable
技术分享 | 抓包分析 TCP 协议
[Li Kou brush questions] 32 Longest valid bracket
js通过数组内容来获取数组下标
js中,字符串和数组互转(二)——数组转为字符串的方法
Yyds dry inventory run kubeedge official example_ Counter demo counter
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
El table table - sortable sorting & disordered sorting when decimal and% appear
[go][转载]vscode配置完go跑个helloworld例子
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
967- letter combination of telephone number
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
039. (2.8) thoughts in the ward
ICML 2022 | flowformer: task generic linear complexity transformer
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
js中,字符串和数组互转(一)——字符串转为数组的方法