enow.com Web Search

Search results

  1. Results from the WOW.Com Content Network
  2. String[][] arrays = new String[][] { array1, array2, array3, array4, array5 }; (The latter syntax can be used in assignments other than at the point of the variable declaration, whereas the shorter syntax only works with declarations.) answered Jan 24, 2011 at 10:54. Jon Skeet.

  3. (Pure dynamic arrays do not exist in Java. Instead, List is most encouraged.) To declare a static array of Integer, string, float, etc., use the below declaration and initialization statements. int[] intArray = new int[10]; String[] intArray = new int[10]; float[] intArray = new int[10]; // Here you have 10 index starting from 0 to 9

  4. Here's a simple method that will concatenate two arrays and return the result: public <T> T[] concatenate(T[] a, T[] b) { int aLen = a.length; int bLen = b.length ...

  5. Converting array to list in Java - Stack Overflow

    stackoverflow.com/questions/2607289

    You can, however, have a List<Integer> using the Integer class that wraps the int primitive. Convert your array to a List with the Arrays.asList utility method. Integer[] numbers = new Integer[] { 1, 2, 3 }; List<Integer> list = Arrays.asList(numbers); See this code run live at IdeOne.com.

  6. Learn how to find the maximum or minimum value in an array of primitives using Java with simple and efficient methods. Compare different solutions and see the best practices.

  7. Swap the elements at the start and the end index. Step 2. Increment the start index decrement the end index. Step 3. Iterate Step 1 and Step 2 till start index < end index. For this, the time complexity will be O (n) and the space complexity will be O (1) Sample code for reversing an array in space is like:

  8. java - Create ArrayList from array - Stack Overflow

    stackoverflow.com/questions/157944

    Until Java 16 the javadoc stated: The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations.

  9. How to use java.util.Arrays - Stack Overflow

    stackoverflow.com/questions/5570882

    java.util.Arrays only exposes static methods, so you simply pass in your array and whatever other params are necessary for the particular method you are calling. For instance Arrays.fill(myarray,true) would fill a boolean array with the value true. Here is the javadoc for java.util.Arrays

  10. How do I fill arrays in Java? - Stack Overflow

    stackoverflow.com/questions/576855

    Array elements in Java are initialized to default values when created. For numbers this means they are initialized to 0, for references they are null and for booleans they are false. To fill the array with something else you can use Arrays.fill () or as part of the declaration. int[] a = new int[] {0, 0, 0, 0};

  11. It's not very convenient writing Arrays.toString(arr);, then importing java.util.Arrays; all the time. Please note, this is not a permanent fix by any means. Just a hack that can make debugging simpler. Printing an array directly gives the internal representation and the hashCode. Now, all classes have Object as the parent-type.