How to create array of strings in Java?


In Java, you can create an array just like an object using the new keyword. The syntax of creating an array in Java using new keyword −

type[] reference = new type[10];

Where,

  • type is the data type of the elements of the array.

  • reference is the reference that holds the array.

And, if you want to populate the array by assigning values to all the elements one by one using the index −

reference [0] = value1;
reference [1] = value2;

You can declare an array of Strings using the new keyword as &mius;

String[] str = new String[5];

And then, you can populate the string using the indices as −

str[0] = "JavaFX";
str[1] = "OpenCV";
str[2] = "ApacheFlume";
str[3] = "Apache Hadoop";
str[4] = "WebGL";

You can also create a String array directly using the curly braces as −

String str = str[0] = {"JavaFX", "OpenCV", "ApacheFlume", "Apache Hadoop", "WebGL"}

Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.

Updated on: 19-Dec-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements