java - 我需要在 Map 中保存多个 int 值

标签 java list dictionary integer

我需要创建一种书籍索引方法,该方法可以将多个值与一个键配对

例如 key - “贝克,肯特” 值 - 27 23 76

这可能吗?

导入ou.*;是开放大学图书馆,不应该影响任何事情。

import java.util.*;
import ou.*;
public class BookIndex
{

public Map<String, Integer> index()
{
   Map<String, Integer> actual = new HashMap<>();
   return actual;
}

谢谢

最佳答案

Map<String, Integer>中使用整数数组而不是整数怎么样? .

 HashMap<String, Integer[]> anewMap = new HashMap<String, Integer[]>();

 anewMap.put("Beck,Kent",new Integer[] { 27, 23, 76});

关于java - 我需要在 Map 中保存多个 int 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16377404/

相关文章:

javascript - 嵌套有序切换列表,不重复

c# - 如何让用户编辑list<T>内容?

python - 检查 float 是否在 Python 的字典键中

java - 为什么 HashMap "contain"不只包含内部更改的键?

python:使用通配符快速查找字典单词*

java - 使用普通 JAVA Stream 收集 int 数组的值

python - 根据另一个列表的内容从一个列表中删除项目

Java NIO : reading variable-sized blocks

java - Tomcat 和 Oracle DB 上的 JasperServer 部署 (Solaris)

java - ArrayList 到数组