About 22,800,000 results
Open links in new tab
  1. How to Initialize an Array in Java? - GeeksforGeeks

    Apr 14, 2025 · In this article, we will discuss different ways to declare and initialize an array in Java. Understanding how to declare an array in Java is very important. In Java, an array is declared by specifying its data type, and an identifier, and adding brackets [] …

  2. Java Arrays - W3Schools

    Java Arrays. Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets:

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

    Jul 29, 2009 · There are various ways in which you can declare an array in Java: float floatArray[]; // Initialize later int[] integerArray = new int[10]; String[] array = new String[] {"a", "b"}; You can find more information in the Sun tutorial site and the JavaDoc.

  4. Arrays in Java - GeeksforGeeks

    Mar 28, 2025 · To declare an array in Java, use the following syntax: type [] arrayName; type: The data type of the array elements (e.g., int, String). arrayName: The name of the array. Note: The array is not yet initialized. 2. Create an Array. To create an array, you need to allocate memory for it using the new keyword:

  5. How to Fill (initialize at once) an Array in Java?

    Jan 11, 2025 · There are mutiple ways to fill an array in Java. They are as follows: 1. Declare them at the time of the creation. In this method, we declare the elements of the array at the time of the creation itself. Example: Output: 2. Using Arrays.fill () Method. java.util.Arrays.fill () method is in java.util.Arrays class.

  6. Initializing Arrays in Java - Baeldung

    Dec 16, 2024 · In this tutorial, we’ll see how to declare an array. Also, we’ll examine the different ways we can initialize an array and the subtle differences between them. Read more. 2. Understanding Arrays. In Java, arrays are objects that can store multiple elements of …

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

    But in Java, how can I initialize all the elements to a 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).

  8. How to manually set an array in Java? - Stack Overflow

    Mar 19, 2016 · How do you manually assign variables to an array? I have a code fragment below. I don't want to manually put shortStraight[0] = "211100", shortStraight[1] = "021110", and so on. Any help? public Sample () { shorty = new String [12];

  9. Arrays in Java: A Reference Guide - Baeldung

    Jul 24, 2024 · In this tutorial, we’ll deep dive into a core concept in the Java language – arrays. We’ll first see what’s an array, then how to use them; overall, we’ll cover how to: 2. What’s an Array? First things first, we need to define what’s an array?

  10. How to Declare and Initialize an Array in Java - HowToDoInJava

    Learn to declare and initialize arrays in Java using direct statements, java.util.Arrays class and Stream API with examples.

  11. Some results have been removed
Refresh