如果我有一个类需要返回一个变量维的字符串数组(并且该维度只能在运行该类的某个方法时确定),那么如何在类的构造函数中声明动态数组呢? / p>
如果问题不够明确,
在php中我们可以简单地将字符串数组声明为 $ my_string_array = array(); 并通过 $ my_string_array [] =新值添加元素;
上面的代码是什么,然后在java中?
解决方案您将需要查看 java.util包,特别是 ArrayList 类。它有一些方法,如 .add()。remove()。indexof()。contains()。toArray()等等。
If I have a class that needs to return an array of strings of variable dimension (and that dimension could only be determined upon running some method of the class), how do I declare the dynamic array in my class' constructor?
If the question wasn't clear enough,
in php we could simply declare an array of strings as $my_string_array = array(); and add elements to it by $my_string_array[] = "New value";
What is the above code equivalent then in java?
解决方案You will want to look into the java.util package, specifically the ArrayList class. It has methods such as .add() .remove() .indexof() .contains() .toArray(), and more.
更多推荐
如何在java中初始化动态数组?
发布评论