0

Is it possible to create an array of Label[] without setting the initial array size Label[22]?

Label[] l = new Label[22];

for (int i = 0; i < 10; i++) {
    l[i] = new Label(String.valueOf(i));
    l[i].setMinSize(100, 32);
    vbox.getChildren().add(l[i]);
}
Program-Me-Rev
  • 5,318
  • 11
  • 47
  • 109
  • 3
    At some point, you MUST define the size of an array, that's how they work, if you want something more dynamic, then you should use some kind of `List`, like `ArrayList` – MadProgrammer Jan 15 '17 at 23:13
  • Hi. Thanks for the reply @MadProgrammer. How can I implement dynamic **Labels** via **Lists** instead of an **Array**? Could you please give me a small illustration? I'm willing to accept it as an answer. – Program-Me-Rev Jan 15 '17 at 23:47
  • 2
    You just have to think of a `List` as been a "dynamic array" - Start by having a look at [the Collections Trail](https://docs.oracle.com/javase/tutorial/collections/) – MadProgrammer Jan 15 '17 at 23:49
  • 1
    Take a look at the [SO Documentation](http://stackoverflow.com/documentation/java/90/collections/386/declaring-an-arraylist-and-adding-objects#t=201701152349482702294) – James_D Jan 15 '17 at 23:50

0 Answers0