How to initialize dynamic arrays in Java?
•
Java
If I have a class that needs to return a string array of variable dimensions (and the dimension can only be determined when running some methods of the class), how can I declare a dynamic array in the constructor of the class?
If the problem is not clear enough,
In PHP, we can simply declare an array of strings as $my_ string_ array = array(); And pass $my_ string_ Array [] = "new value" add element;
What is the above code?
Solution
You will need to view Java Util package, especially the ArrayList class It has methods such as add(). remove(). indexof(). contains(). ToArray () and so on
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码