如何字符串转换为数组的名字吗? [英] How to convert String to the name of the Array?
本文介绍了如何字符串转换为数组的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有大量的包含不同的数据阵列。每个人都有,看起来这名: rsf_wings,isa_wings,isa_ships,isa_civs
等
我有建立一个字符串arrayName中
出来传递给它的各个组成部分的功能:
公共静态无效AddShips(FAC字符串,字符串型)
{
string成员= NULL;
字符串arrayName中= FAC +_+类型;
}
现在我需要一些方法来转换该 arrayName中以数组的实际名称。大致应该是这样的:
成员= arrayName中的[(INT)(arrayName.length *的Math.random());
解决方案
没有办法做到这一点在Java中。而是使用一个Map按名称顺序来存储不同的阵列。
地图<弦乐,INT []> arrayMap ...
INT [] myArray的= arrayMap.get(arrayName中);
I have a large number of arrays containing different data. Each has a name that looks this: rsf_wings, isa_wings, isa_ships, isa_civs
etc.
I have a function that builds a String arrayName
out of various components passed to it:
public static void AddShips(String fac, String type)
{
String member = null;
String arrayName = fac+"_"+type;
}
Now I need some way to convert this arrayName to the actual name of the array. Roughly it should look like this:
member = arrayName[(int) (arrayName.length * Math.random())];
解决方案
No way to do it in Java. Instead use a Map in order to store the different arrays by name.
Map<String, int[]> arrayMap ...
int[] myArray = arrayMap.get(arrayName);
这篇关于如何字符串转换为数组的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文