-3

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
    Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. It is unclear what you are asking or what the problem is. Please [edit] your question to include a detailed description what you mean by "identifier for an array". If possible, show the source code you have and what you are trying to do. – Progman May 18 '23 at 14:07
  • 2
    Are you looking for https://stackoverflow.com/questions/1647260/java-dynamic-array-sizes? – Progman May 18 '23 at 14:08
  • 1
    What? Please show an example of what you are trying to accomplish. You want an ArrayList? – OldProgrammer May 18 '23 at 14:09
  • The identifier is the same as identifiers for arrays which *do* have a known size. I certainly hope you are not naming fields `arrayOfTenStrings`. – VGR May 18 '23 at 17:09

1 Answers1

1

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]);
Stone
  • 155
  • 1
  • 6