How to define a Java string array
In Java, you can define a string array using the following method:
- Define a string array using array literal notation.
String[] myArray = {"Hello", "World", "Java"};
- Define a string array using the new keyword and specifying the array size.
String[] myArray = new String[3];
myArray[0] = "Hello";
myArray[1] = "World";
myArray[2] = "Java";
- Define a string array using the new keyword and initialize it with string values.
String[] myArray = new String[]{"Hello", "World", "Java"};
No matter how you define a string array, it is important to note that the array index starts at 0.