Skip to content

Is it required to specify type of data to both diamond operators while creating object?

I am creating an object of ArrayAdapter in Java(Android Studio) is it required to add String Data type to both sides inside the diamond operators? can anyone explain

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<"here">(this,android.R.layout.simple_list_item_1,numbersInChars);



No, you do not need to specify it on the right side. However, it won’t cause any harm if you specify there. Please read more about the diamond at Given below is an example from the same page:

Box<Integer> integerBox = new Box<>();

As you can see Integer has not been specified on the right side. However, if you wish, you can write it as follows as well:

Box<Integer> integerBox = new Box<Integer>();