About 169,000 results
Open links in new tab
  1. How do I declare and initialize an array in Java?

    Jul 29, 2009 · You can either use array declaration or array literal (but only when you declare and affect the variable right away, array literals cannot be used for re-assigning an array). For primitive types: int[] myIntArray = new int[3]; // each element of the array is initialised to 0 int[] myIntArray = {1, 2, 3}; int[] myIntArray = new int[]{1, 2, 3 ...

  2. Java: how to initialize String []? - Stack Overflow

    Apr 1, 2010 · In Java 8 we can also make use of streams e.g. String[] strings = Stream.of("First", "Second", "Third").toArray(String[]::new); In case we already have a list of strings (stringList) then we can collect into string array as: String[] strings = stringList.stream().toArray(String[]::new);

  3. Java - How do I make a String array with values?

    Dec 18, 2011 · Create array from a string Hot Network Questions Is it a faux pas for a reviewer of a published math paper to immediately solve/publish problems it leaves open?

  4. java - Any way to declare an array in-line? - Stack Overflow

    Feb 28, 2016 · You are right, when I wrote this I hadn't used varargs much--and I used array initialization quite a bit before varargs existed in java. The one part I'd still prefer arrays for is that if you define it as an aray you can make it a constant at the top of the file instead of inline data, and you can also extract it to a config file

  5. How can I declare dynamic String array in Java - Stack Overflow

    Apr 28, 2015 · I am using String Array declare as zoom z[]=new String[422];. But this array stores value from 0 to 32, so I got null pointer exception after looping value 32.

  6. How can I initialize a String array with length 0 in Java?

    The Java Docs for the method String[] java.io.File.list(FilenameFilter filter) includes this in the returns description: The array will be empty if the directory is empty or if no names were accepted by the filter. How do I do a similar thing and initialize a String array (or any other array for that matter) to have a length 0?

  7. How to declare a static string array in Java? - Stack Overflow

    May 2, 2013 · To initialise an array at construction time you can specify a list values in curly braces: private static final String[] STRING_ARRAY = {"foo", "bar", "baz"}; In my example I have assumed that you won't want to change the instance of array and so have declared it final. You still would be able to update individual entries like so: array[0] = "1";

  8. String array initialization in Java - Stack Overflow

    First up, this has got nothing to do with String, it is about arrays.. and that too specifically about declarative initialization of arrays. As discussed by everyone in almost every answer here, you can, while declaring a variable, use:

  9. java - Create a two dimensional string array anArray [2] [2] - Stack ...

    Dec 3, 2013 · The question: 3. Create a Java program called TwoDimArray and implement the following: Create a two dimensional string array anArray[2][2]. Assign values to the 2d array containing any Country and associated colour. Example: France Blue Ireland Green Output the values of the 2d array using nested for loops.

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

    Jul 23, 2017 · @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