About 380,000 results
Open links in new tab
  1. java - Any shortcut to initialize all array elements to zero? - Stack ...

    For type int, the default value is zero, that is, 0. If you want to initialize an one-dimensional array to a different value, you can use java.util.Arrays.fill() (which will of course use a loop internally).

  2. How to Initialize an Array with 0 in Java - Java2Blog

    May 17, 2022 · This article discusses the arrays and different ways to initialize an array with 0 in Java.

  3. Initializing Arrays in Java - Baeldung

    Dec 16, 2024 · In this article, we explored different ways of initializing arrays in Java. Also, we learned how to declare and allocate memory to arrays of any type, including one-dimensional and multi-dimensional arrays.

  4. Creating an int array filed with zeros in Java - Stack Overflow

    May 18, 2018 · I want to create a 10 dimensional array that's filled with zeros. If I simply use int[] array = new int[10]; do I have a guarantee that all int's in the array are zeros?

  5. How to Initialize All Array Elements to Zero in Java

    Feb 12, 2024 · In this article, readers can look forward to gaining a comprehensive understanding of various methods to re-initialize an array to zero in Java. The content will cover multiple techniques, including the use of for loops, Arrays.fill(), …

  6. How to Initialize an Array in Java? - GeeksforGeeks

    Apr 14, 2025 · In Java, an array can be initialized by default values when the size of the array is declared with rectangular brackets [ ]. int [] arr = new int [20]; // Array of size 20, initialized with default values (0) We can specify the size of an array at the time of initialization.

  7. How do I declare and initialize an array in Java?

    Jul 29, 2009 · The third way of initializing is useful when you declare an array first and then initialize it, pass an array as a function argument, or return an array. The explicit type is required. String[] myStringArray; myStringArray = new String[]{"a", "b", "c"};

  8. How to initialize an array with zero values in Java

    Mar 1, 2021 · On a specific occasion, you need to initialize an array with zero values. This article will take you through the pros and cons of the various way how to initialize Java array with default zero values.

  9. Java Initialize an Array with 0 [4 ways] - Blogger

    In this post, I will be sharing how to initialize an Array with 0 in Java. There are 4 ways to achieve our goal: 1. Using default initialization of Array 2. Using the Arrays.fill() method 3. Using declaration and initialization simultaneously 4. Using for loop Read Also: Find first non-repeated element in integer array in Java Java Initialize ...

  10. Java Array Declaration – How to Initialize an Array in Java with ...

    Sep 9, 2021 · There are two ways you can declare and initialize an array in Java. The first is with the new keyword, where you have to initialize the values one by one. The second is by putting the values in curly braces.

Refresh