EN
Java - create array
3
points
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]