[Solved] Array test for a string [duplicate]


String[] strarray = new String[0]; will create empty array.

You need change to String[] strarray = new String[1];

or add strarray.length > 0 to if condition if (strarray.length > 0 && strarray[0].isEmpty())
to prevent array out of bounds exception

Update: it throw null pointer exception if you did init array.

String[] strarray = new String[1];
strarray[0] = "Your string";

If you dont want to init at first time, you should check null before use it before isEmpty() and contains()

public static boolean isNullOrEmpty(String str) {
        return str==null || str.isEmpty();
 }

8

solved Array test for a string [duplicate]