java - How do I add arrays to an Arraylist of Arrays (Arraylist)
问题描述
I want to save the steps pf my player-character in a Sokoban-game. So at first i want to fill an Array of int x and y, called "pos" with the actual position of the character. And than i want to add this array to an ArrayList of Arrays, called "moves".
Array for one player-position:
int[] pos = new int [2];
ArrayList for all steps, the player made in the level:
Arraylist<Integer[]> moves = new ArrayList<>();
"int[]" makes an error, if placed inside the pointy brackets at the ArrayList.
How do i add the Array pos to the ArrayList moves?
解决方案
这完全适用于int[]。但是int[] != Integer[],在两个地方都使用相同的。
int[] pos = new int[2];
ArrayList<int[]> arrayList = new ArrayList<>();
pos[0] = 1;
pos[1] = 2;
arrayList.add(pos);
System.out.println(arrayList.get(0)[0]+ " "+ arrayList.get(0)[1]);
推荐阅读
- outlook - Outlook 更新后 iCal 日历事件不再取消
- go - 来自 xx.xx.xx.xx:14333 的 TLS 握手错误:EOF
- elasticsearch - 如何使用 mutate gsub 从登录过滤器块中删除换行符
- python-3.x - 如何拆分字典中定义的长正则表达式模式
- angularjs - 如何找到 AngularJS 性能缓慢的原因?
- django - 如何将文件从 React-native 上传到 S3 并通过 REST API 存储文件名
- vuejs2 - 如何为 v-for 定位对象
- java - 如何使用资源尝试将 S3Object 转换为 File 并在 Java 中返回 File Object?
- python - 如何确保单词的颜色不是单词所说的颜色
- apache - 强制 SSL 维护 URL