How to Declare a String Array in Java

Strings can be declared in java using the keyword new as shown in the below example. Without using the keyword new also it can be declared as shown below. The following example illustrates how to declare a string and how to initialize it.

String arrays can be declared in Java by the following syntax.

String first[] = new String[] {"gopi", "krishnamma", "udhaya", "priya"};

String second[] = {"ravi", "bindhu", "ramya", "rama"};

For two dimensional arrays,

String twod[][] = {
            {"a", "b"},
            {"c", "d"}}

No comments:

Post a Comment

My Profile