Languages
[Edit]
EN

Java - create new array of strings

0 points
Created by:
Geo-Baby
240

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]

Java - Arrays (popular problems)

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