如何字符串转换为数组的名字吗?

编程入门 行业动态 更新时间:2024-10-18 18:17:33
本文介绍了如何字符串转换为数组的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有大量的包含不同的数据阵列。每个人都有,看起来这名: 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);

更多推荐

如何字符串转换为数组的名字吗?

本文发布于:2023-11-08 20:21:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   转换为   字符串   名字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!