类似于Python的Java字典

2024-09-30 20:38:48 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我已经搜索了一整天,但我似乎找不到如何创建我用Python创建的字典,以及如何用Java创建类似的东西。我试过查看数组列表和列表等,但没有用。在

PIECESDICT = {1: [[0,0], [0,1], [0,2], [1,1]], 2: [[0,0], [1,0], [0,1]], 3: [[0,0], [0,1], [1,1]], 4: [[0,0], [0,1], [1,0], [1,1]], 5: [[0,0], [1,0], [2,0]]} 

所以这是我的字典,基本上它所做的就是,从coords(0,0)是每一个片段的左上角开始。它本身就是一部分。在

例如,第1件看起来像:

^{pr2}$

类似地,第2部分看起来像:

00
0

Tags: 列表字典数组javacoordspr2piecesdict
3条回答

看起来你想。。。某一对或坐标对象的^{}s^{}。在

如果您有一个接受坐标作为参数的Pair类(例如new Pair(0, 0)),那么您可以执行如下操作:

HashMap<Integer, ArrayList<Pair>> map = new HashMap<Integer, ArrayList<Pair>>();

ArrayList<Pair> first = new ArrayList<Pair>();
first.add(new Pair(1, 2));
first.add(new Pair(3, 4));

map.put(1, first);

// map == {1: [[1,2], [3,4]]}

HashMap也可以接受String(而不是Integer)作为其中列表的键。在

HashMap呢? 例如: 地图.put(“名称”、“值”)

你可以试试^{}

使用方法:

Map<Integer, Integer[][]> map = new HashMap<Integer, Integer[][]>();
Integer[][] v1 = { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 1 } };
map.put(1, v1);

相关问题 更多 >