How to initialize all the elements of an array to any specific value in java

后端 未结 10 1455
故里飘歌
故里飘歌 2020-12-12 17:33

In C/C++ we have memset() function which can fulfill my wish but in Java how can i initialize all the elements to a specific value? Wh

相关标签:
10条回答
  • 2020-12-12 18:33

    There's also

    int[] array = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
    
    0 讨论(0)
  • 2020-12-12 18:33

    Evidently you can use Arrays.fill(), The way you have it done also works though.

    0 讨论(0)
  • 2020-12-12 18:34

    You can use Arrays.fill(array, -1).

    0 讨论(0)
  • 2020-12-12 18:35

    Have you tried the Arrays.fill function?

    0 讨论(0)
提交回复
热议问题