English 中文(简体)
我可以自定义 Java 矩阵的索引吗?
原标题:Can I customize the index of a matrix in Java?

我想在爪哇执行一个带有类似此示例的自定义索引的矩阵 :

         country1 city1 name1 region1 population1
country2    23      5    55    ...
city2       5       9    .
name2                    .
region2                  .
population2

That is mat[country1][country2] should return 23. I don t know how I will do it.

最佳回答

您可能不得不使用 Hashmap 或 Hashtable 或 Hashtable 配对键来包含两个索引 : Map<Pair<K1,K2>, V>

You can take a look at that for more informations: Map with two-dimensional key in java

问题回答

如果您有二维表格, 其行和列总是遵循此顺序, 那么您可以使用列/列的列表 。

例如:

   public static final int COUNTRY = 0;
   public static final int CITY  = 1;
   public static final int NAME = 2;
   public static final int REGION = 3;
   public static final int POPULATION = 4;

另一方面,如果在数据结构中,在两个维度中,可以有两个国家,那么你就可以使用地图。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签