开发者

How to create array with same name from its function input parameter

How can I fix this:

class Name {

public void createArray(String name)
{
 String name=new String[200];//we know, we can't do this- duplicate local variable,need a fix here.
}
  }

I want to create array of strings with name of array as input parameter = name, Example:

1) for function call createArray(domain1) -> I need essentially this to happen-> S开发者_开发技巧tring domain1=new String[200];

2)for function call createArray(domain22)-> I need function to create String domain22=new String[200]; Hope this edit helps. NOTE: There is a possibility that same name is passed byfunction twice/thrice. like createArray(domain1);, at that point of time I want to ignore the creation of array.


Store your new String[200] objects in a Map keyed by the name

Map<String, String[]> myarrays = new HashMap<String, String[]>();

myarrays.put("name", createArray("name"));
myarrays.put("test", createAray("test"));

then when you want one of them do

String[] data = myarrays.get("test");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜