▚ 01 Int2LongOpenHashMap介绍
该API
接口的链接为【网址】。
1.1 构造函数说明
1.2 功能函数说明 (部分)
▚ 02 代码示例
import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap;
import java.util.Random;
public class int2LongOpenHashMap {
public static void main(String[] args) {
Int2LongOpenHashMap hash = new Int2LongOpenHashMap(); // Creates a new hash map
int maxNum = 100;
int count = 10;
Random random = new Random();
int index;
long key;
for (int i = 0; i < count; i++) {
index = random.nextInt(maxNum);
key = (long) index * Integer.MAX_VALUE;
hash.put(i, key); // Adds a pair to the map
}
if (hash.isEmpty()) {
System.out.println("the hash is empty.");
} else {
System.out.println("the hash is not empty.");
}
if (hash.containsKey(5)) {
System.out.println("contain <5, " + hash.get(5) + ">");
} else {
System.out.println("not contain key=5.");
}
for (int i = 0; i < hash.size(); i++) { // Returns the number of key/value mappings in this map
System.out.println(i + ": " + hash.get(i));
}
}
}
▚ 03 编译&运行
3.1 下载fastutil-xxx.jar
fastutil-xxx.jar下载地址为:https://www.mvnjar.com/it.unimi.dsi/fastutil/8.2.1/detail.html
3.2 编写脚本(编译+运行)
🍖
Linux
下运行Java
程序时,如何添加第三方jar
包,可参考博客【Java: 引用第三方jar包来运行Java程序:https://blog.csdn.net/Xminyang/article/details/108011133】
- 🍎 脚本run.sh包括4部分:编译
*.java
文件为*.class
,将*.class
打包为.jar
,删除*.class
文件,最后运行程序。run.sh
内容如下:
echo "1. Compiling..."
javac -cp ./fastutil-8.5.8.jar int2LongOpenHashMap.java
echo "2. Making jar archive..."
jar cf Run-1.0.jar int2LongOpenHashMap.class
echo "3. Deleting *.class..."
rm -rf int2LongOpenHashMap.class
echo "4. Running..."
java -cp ./fastutil-8.5.8.jar:./Run-1.0.jar int2LongOpenHashMap
3.3 结果截图
🍎 本文基于Windows下的集成开发环境VS Code来编译、运行。
![](https://i-blog.csdnimg.cn/blog_migrate/1b8c4455ff4219078a79c2f06a26bd28.gif#pic_center)