is there anyway of unspecifying the size of an array so the number of elements input can vary each time?
I'm currently using an array to store values entered which are then manipulated but the array is set to 100000 and is creating problems.
The rules about Java arrays are pretty strict when it comes to size: once established, there's no change.
But there is a usefull class in java.util package called ArrayList. That collection works just like an array except that you can change the size by adding/removing members.
Moreover, starting from JDK 5.0, you can add type to the arraylists (wasn't possible prior 5.0, ArrayList returned objects of type Object). Word of caution: generic array lists cannot be of primitive type, but the wrapper classes do the trick
Code:
import java.util.*
public class SomeName{
ArrayList a <theType>= new ArrayList<theType>(some members);
...//some code
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.