0

I want to check the condition whether string array gives value or null.

String function:

String rowData[] = (String[]) ArrayUtils.subarray(DataArray, startIndex,
                                         (startIndex + maxColumnCount));

if(rowData not null)
{

}

Value of data array is coming by:

String DataArray[] = request.getParameter("values").split(",");

What would be in if Condition?

3 Answers3

1

Check the length/size of the array is zero or not

if(DataArray.length != 0)  //something similar to this
Praveen
  • 55,303
  • 33
  • 133
  • 164
0

The request parameter could not have been given and yield null.

String dataArrayParam = request.getParameter("values");
String[] dataArray = dataArrayParam == null?
    new String[0] : dataArrayParam.split(",");

In general it would be:

if (rowData != null) {

BTW. String[] is a more conventional notation, String a[] comes from C compatibility in the early days of Java.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
0

Simply check

if(DataArray != null)
{
     String rowData[] = (String[]) ArrayUtils.subarray(DataArray, startIndex,
                                         (startIndex + maxColumnCount));

     if(rowData not null)
     {

     }
}
Master
  • 2,945
  • 5
  • 34
  • 65