How do I create an identifier for an Array of Strings without a predefined size in java?

58 views Asked by At

I am trying to figure out how do I create an identifier for an array of Strings which doesn't have a predefined set number of Strings in it?

I couldn't find a solution for this specific problem when searching on the internet thats why I'm asking here.

1

There are 1 answers

0
Stone On

You could create one "ArrayList" collection and store any number of "String" objects in it. And finally you could convert the "ArrayList" to "String[]".

List<String> list = new ArrayList<>();
list.add("String1");
...
String[] array = list.toArray(new String[0]);