简体   繁体   English

Java中的2D数组,使用包含特殊字符作为索引的字符

[英]2D array in Java using characters including special characters as index

Is it possible to create a 2d array in java, such the column and row names are letter-characters and we can access like array[E][*] = ... ? 是否有可能在java中创建一个二维数组,例如列和行名称是字母字符,我们可以访问像array[E][*] = ...

Here we can't use map because Map corresponds to 1-D array. 这里我们不能使用map,因为Map对应于1-D数组。 So what will be the other alternatives ? 那么其他选择会是什么呢?

As you said in the comments that Map corresponds to 1D array, why not use Map of Maps. 正如您在评论中所说的Map对应一维数组,为什么不使用Map of Maps。

Map<Character,Map<Character,Character>> outerMap = new HashMap<Character, Map<Character, Character>>();

and use a simple method to fetch your data: 并使用一种简单的方法来获取您的数据:

public char getValue(char row ,char column, Map<Character,Map<Character,Character>> outerMap) {

return  outerMap.get(row).get(column);

}

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM