You can’t modify the size of an array. So you need to instantiate a new array. You have to use an ArrayList which extends as per the real-time requirements.
Check the below code which uses ArrayList.toArray( T[] a ):
List<String> where = new ArrayList<String>();
where.add( ContactsContract.Contacts.HAS_PHONE_NUMBER+"=1" );
where.add( ContactsContract.Contacts.IN_VISIBLE_GROUP+"=1" );
To convert it to a simple array, you can do this:
String[] simpleArray = new String[ where.size() ];
where.toArray( simpleArray );
Or else you can do it like below:
// iterate over the array
for( String oneItem : where ) {
...
}
// get specific items
where.get( 1 );