An elegant way of initialising an empty String array in Java

后端 未结 2 2025
难免孤独
难免孤独 2021-01-17 07:46

In the current code base that I\'m working on I find myself needing to initialise many empty String[] of different lengths.

As of now, they are always initialised in

相关标签:
2条回答
  • 2021-01-17 08:04

    Using Arrays.fill:

    String[] a = new String[9];
    Arrays.fill(a, "");
    
    0 讨论(0)
  • 2021-01-17 08:17

    You can use Arrays.fill method: -

    Arrays.fill(a, "");
    
    0 讨论(0)
提交回复
热议问题