About 132,000 results
Open links in new tab
  1. arrays - length and length () in Java - Stack Overflow

    Dec 27, 2009 · In Java, an Array stores its length separately from the structure that actually holds the data. When you create an Array, you specify its length, and that becomes a defining attribute of the Array. No matter what you do to an Array of length N (change values, null things out, etc.), it will always be an Array of length N.

  2. How can I get the size of an array, a Collection, or a String in Java ...

    May 19, 2014 · An array creation expression specifies the element type, the number of levels of nested arrays, and the length of the array for at least one of the levels of nesting. The array's length is available as a final instance variable length. An array initializer creates an array and provides initial values for all its components.

  3. Getting the array length of a 2D array in Java - Stack Overflow

    In this case, we access [1, 1, 1, 1] and thus, the number of columns = 4. When you're given a problem where you can't see the array, you can visualize the array as a rectangle with n X m dimensions and conclude that we can get the number of columns by accessing the first array then its length. The other one (arr.length) is for the rows.

  4. Variable length (Dynamic) Arrays in Java - Stack Overflow

    Feb 2, 2024 · In Java, "normal" arrays are fixed-size. You have to give them a size and can't expand them or contract them. To change the size, you have to make a new array and copy the data you want - which is inefficient and a pain for you. Fortunately, there are all kinds of built-in classes that implement common data structures, and other useful tools too.

  5. How do I declare and initialize an array in Java? - Stack Overflow

    Jul 29, 2009 · maybe important to note that multi-dimensional arrays are actually arrays of arrays, so int[][] array = new int[2][]; is creating an array with 2 positions (that can hold an int[] array each) initialized with null (e.g. array[1] returns null; array[1][0] throws a NullPointerException)

  6. java - Length of byte [] array - Stack Overflow

    Mar 12, 2014 · Array Members: The members of an array type are all of the following: The public final field length, which contains the number of components of the array. length may be positive or zero. length is a property, not a method. You should write: bytes.length

  7. java - Getting the length of two-dimensional array - Stack Overflow

    nir is an array of int arrays; you've got two arrays of length three. System.out.println(nir[0].length); would give you the length of your first array. Also worth noting is that you don't have to initialize a multi-dimensional array as you did, which means all …

  8. java - Where is array's length property defined? - Stack Overflow

    Feb 16, 2012 · Similarly we can determine the length of an Array object using the length property. String[] str = new String[10]; int size = str.length; Whereas the size() method of ArrayList is defined inside the ArrayList class, where is this length property of Array defined?

  9. Multidimensional Arrays lengths in Java - Stack Overflow

    May 11, 2011 · In Java we can't use Length field like we used to one-dimensional arrays. So simply writing a few lines of code solves this problem. First, you need to know that the output of the Length field in multidimensional arrays is the number of rows.I mean when you have below array. int[][] numbers = {{1,2,3,4,2,6},{4,5,6,7}};

  10. java - Length of an object array - Stack Overflow

    Nov 26, 2012 · Indeed, array length is not a method. But you still use that to determine the length of an array. Are you saying that myArray.length() works for String or int/Integer array? Anyway, when using array in Java, always consider if using ArrayList would suit your purpose better.

Refresh