Languages
[Edit]
EN

Java - create new array of strings

0 points
Created by:
Geo-Baby
300

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]

Alternative titles

  1. Java - declare and initialize array of strings
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 new array of strings

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