0 votes
1 view
in Java by (3.5k points)

I have the following code:

String[] where;

where.append(ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1");

where.append(ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1");

Those two appends are not compiling. How would that work correctly?

1 Answer

0 votes
by (34.9k points)

The extent of an array can't be altered. If you require a bigger array you ought to instantiate a new one.

A better resolution would be to apply an ArrayList which can develop as you need it. The program ArrayList.toArray( T[] a ) gives you back your array if you require it in this form.

List<String> where = new ArrayList<String>();

where.add( ContactsContract.Contacts.HAS_PHONE_NUMBER+"=1" );

where.add( ContactsContract.Contacts.IN_VISIBLE_GROUP+"=1" );

If you require to alter it to a simple array...

String[] simpleArray = new String[ where.size() ];

where.toArray( simpleArray );

But most things you do with an array you can be donewith this ArrayList, too:

// iterate over the array

for( String oneItem : where ) {

    ...

}

// get specific items

where.get( 1 );

...