About 93,300 results
Open links in new tab
  1. How do I declare and initialize an array in Java? - Stack Overflow

    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"};

  2. How to initialize an array in Java? - Stack Overflow

    Dec 21, 2009 · When you create an array of size 10 it allocated 10 slots but from 0 to 9. This for loop might help you see that a little better. public class Array { int[] data = new int[10]; /** Creates a new instance of an int Array */ public Array() { for(int i = 0; i < data.length; i++) { data[i] = i*10; } } }

  3. How to initialize all the elements of an array to any specific value …

    Whenever we write int[] array = new int[10], this simply initializes an array of size 10 having all elements set to 0, but I just want to initialize all elements to something other than 0 (say, -1). Otherwise I have to put a for loop just after the initialization, which ranges from index 0 to index size − 1 , and inside that loop assign each ...

  4. What is the default initialization of an array in Java?

    Java says that the default length of a JAVA array at the time of initialization will be 10. private static final int DEFAULT_CAPACITY = 10; But the size() method returns the number of inserted elements in the array, and since at the time of initialization, if you have not inserted any element in the array, it will return zero.

  5. java - Initialize array of primitives - Stack Overflow

    May 27, 2012 · Remember arrays in java are fixed length data structures. Once you create an array, you have to specify the length. Without initialization, the first case is . int[] arr1 = new int[5]; The second case it would be. int[] arr2 = {0,0,0,0,0}; You see the difference?

  6. Double array initialization in Java - Stack Overflow

    It is called an array initializer and can be explained in the Java specification 10.6. This can be used to initialize any array, but it can only be used for initialization (not assignment to an existing array). One of the unique things about it is that the dimensions of the array can be determined from the initializer.

  7. Initialising a multidimensional array in Java - Stack Overflow

    Jul 1, 2009 · Multidimensional Array in Java Returning a multidimensional array. Java does not truely support multidimensional arrays. In Java, a two-dimensional array is simply an array of arrays, a three-dimensional array is an array of arrays of arrays, a four-dimensional array is an array of arrays of arrays of arrays, and so on... We can define a two ...

  8. initializing a boolean array in java - Stack Overflow

    Mar 2, 2010 · Arrays in Java start indexing at 0. So in your example you are referring to an element that is outside the array by one. It should probably be something like freq[Global.iParameter[2]-1]=false; You would need to loop through the array to initialize all of it, this line only initializes the last element.

  9. java - Initialize 2D array - Stack Overflow

    Dec 12, 2012 · I am trying to initialize a 2D array, in which the type of each element is char. So far, I can only initialize this array in the follow way. public class ticTacToe { private char[][] table; pu...

  10. How to make an array of arrays in Java - Stack Overflow

    @Terence: It does the same as the first: It creates an array of string array references, initialized to the values array1, array2, array3, array4 and array5 - each of which is in itself a string array reference. –

Refresh