Java:
String [] as = new String [] {new String ("foo"), new String ("bar")};
This is just initialization of the array with elements while declaring it.
But your question shows a misconception: 'or must you just use the default constructor for creating an array of objects'.
You often declare an array in Java without declaring the elements in the array. You thereby define the size of the array and the types it will contain - however there is no difference between standard-ctor or not.
There is only a difference between embedded types and Objects. If you define an array of embedded types (int, char, boolean, double, ... - sometimes called 'primitive') they get initialized to their default value (0, 0.0 or false).
int [] ia; // only declares the array as of type int
int [] ia = new int [4]; // +size =4, all elements are 0
int [] ia = new int [] {3, 4, 5}; /* elements defined, and
size is implicitly set to 3 */
String [] sa; // only declared, type defined
String [] sa = new String [4]; /* type and size defined
but no elements, no strings defined */
String [] sa = new String [] {new String ("exit")}; /* type defined, size implicitly (1), one element= String defined, using a constructor */
But for a class with a default constructor, which is a constructor which takes no arguments, doesn't get automatically created:
String [] sa = new String [4]; /* no String defined so far,
although there is a standard-CTOR for String */
It is in perfect analogy to simple elements. If you have a class:
class Foo {
int a;
File file;
String s;
}
a is initialized to 0 as a primitive type, but file and s are null, regardless whether there is a standard constructor (for s, there is, for file, there isn't).
std::vector<>should be used in most cases where somebody might use an array.