EN
Java - create new array of strings
0 points
In this article, we would like to show you how to create new array of strings in Java.
Quick solution:
xxxxxxxxxx
1
String[] strings1 = {"A", "B", "C"};
2
String[] strings2 = new String[]{"D", "E", "F"};
3
4
System.out.println(Arrays.toString(strings1)); // [A, B, C]
5
System.out.println(Arrays.toString(strings2)); // [D, E, F]
In this example, we present how to declare or declare and initialize arrays of strings.
xxxxxxxxxx
1
import java.util.Arrays;
2
3
public class Example {
4
5
public static void main(String[] args) {
6
// declare array of strings (size 3)
7
String[] strings = new String[3];
8
9
// declare and initialize arrays
10
String[] strings1 = {"A", "B", "C"};
11
String[] strings2 = new String[]{"D", "E", "F"};
12
13
System.out.println(Arrays.toString(strings1)); // [A, B, C]
14
System.out.println(Arrays.toString(strings2)); // [D, E, F]
15
}
16
}
Output:
xxxxxxxxxx
1
[A, B, C]
2
[D, E, F]