Depends on what it is backed by. If it is for instance java.util.ArrayList
, then you can just use its add()
method:
List<String> list = new ArrayList<String>();
list.add("something");
list.add("something");
list.add("something");
list.add("something");
If you want to use varargs in your DatabaseTable#add()
method, then it should look like:
public void add(String... strings) {
list.addAll(Arrays.asList(strings));
}
or a bit more efficient:
public void add(String... strings) {
for (String string : strings) {
list.add(strings);
}
}
this way you can use it as you wanted:
dt.add("something", "something", "something", "something");
But if it is instead backed by a plain String[]
array, then you'll need to do a bit more work:
private String[] array = new String[0];
public void add(String... strings) {
int length = array.length;
String[] newArray = new String[length + strings.length];
System.arraycopy(array, 0, newArray, 0, length);
array = newArray;
for (int i = 0; i < strings.length; i++) {
array[length + i] = strings[i];
}
}
For more about collections (where ArrayList
fall in) and arrays you may find the Sun tutorials useful: Trial: Collections and Language basics: Arrays.