names[] = {"Ankit","Bohra","Xyz"};
is an initializer and used solely when constructing or creating a new array object. It cannot be used to set the array. You can use it when declared as:
String[] names= {"Ankit","Bohra","Xyz"};
You may also use:
names=new String[] {"Ankit","Bohra","Xyz"};