Do arrays need to be a predefined size?
I need a way to store multiple SQL statements in a String array, but the number of statements are unknown. Can I keep adding onto an array without giving it a pre-defined size? Eventually once the user has performed all the actions needed, I'll create a prepared statement what will read from the array using a 'for' statement and run all the queries that are in the array.
> > You can add,remove elements in a Vector/Arraylist
> but
> > the size of an Array cannot be changed afterwards.
> >
> > correct me if im wrong.
>
> That's right.
>
> *cue the reflection haxors*
Even with reflection there is no possibility of resizing an array, array.length is a public final int.
> Yes they do. What you need is a List, most likely an
> ArrayList:
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/List
> .html
If your only operations are insert a statement and iterate over all statements, you may prefer a LinkedList over an ArrayList. Both will do fine in any case. If you declare the list variable to have type List<String>, you can easily swap between the two as you please.
OleVVa at 2007-7-12 23:01:58 >
