Languages
[Edit]
EN

Java - create array

3 points
Created by:
Payne
654

In this article, we would like to show you how to create an array in Java.

Quick solution:

String[] letters1 = {"A", "B", "C"};
String[] letters2 = new String[]{"D", "E", "F"};

int[] numbers1 = {1, 2, 3};
int[] numbers2 = new int[]{2, 3, 4};

 

Practical example

In this example, we present two methods of how to create arrays in Java.

package tmpOperations3;


import java.util.Arrays;

public class Example {

    public static void main(String[] args) {

        String[] letters1 = {"A", "B", "C"};
        String[] letters2 = new String[]{"D", "E", "F"};

        int[] numbers1 = {1, 2, 3};
        int[] numbers2 = new int[]{2, 3, 4};

        System.out.println(Arrays.toString(letters1));  // [A, B, C]
        System.out.println(Arrays.toString(letters2));  // [D, E, F]

        System.out.println(Arrays.toString(numbers1));  // [1, 2, 3]
        System.out.println(Arrays.toString(numbers2));  // [2, 3, 4]
    }
}

Output:

[A, B, C]
[D, E, F]
[1, 2, 3]
[2, 3, 4]
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - create array

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join