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:
String[] strings1 = {"A", "B", "C"};
String[] strings2 = new String[]{"D", "E", "F"};
System.out.println(Arrays.toString(strings1)); // [A, B, C]
System.out.println(Arrays.toString(strings2)); // [D, E, F]
Practical example
In this example, we present how to declare or declare and initialize arrays of strings.
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
// declare array of strings (size 3)
String[] strings = new String[3];
// declare and initialize arrays
String[] strings1 = {"A", "B", "C"};
String[] strings2 = new String[]{"D", "E", "F"};
System.out.println(Arrays.toString(strings1)); // [A, B, C]
System.out.println(Arrays.toString(strings2)); // [D, E, F]
}
}
Output:
[A, B, C]
[D, E, F]