Reputation: 6983
I'm writing a simple GPS program that stores locations in a array of String
objects. Right now the array is set to 100. When another String
is added, it creates a new String
array of 200, copies the old to the new, then sets the variables equal to the new one. Is there a way to just dynamically enlarge the size of an array, without having to create a new array every time?
Upvotes: 1
Views: 160
Reputation: 874
It sounds like you should use the ArrayList class. It gives you methods for growing your array dynamically.
Upvotes: 4
Reputation: 40744
Or you can use ArrayList<String>
and just keep adding to it as you see fit.
Upvotes: 1
Reputation: 1002
Try a Vector?
Obviously, you could also use any of the other classes in the Java Collections Framework as well, depending on your requirements.
Upvotes: 1