What is the difference between these declarations -
String[] names = {"Max", "Sam", "Ram"};
and
String[] names = new String[]{"Max", "Sam", "Ram"};
What is the difference between these declarations -
String[] names = {"Max", "Sam", "Ram"};
and
String[] names = new String[]{"Max", "Sam", "Ram"};
There is no difference between the two. The first one is just more readable and with less typing.
There is no difference at all. Both objects are immutable, because they cant be changed after declaration.
String[] names = {"Max", "Sam", "Ram"};
String[] names = new String[]{"Max", "Sam", "Ram"};
In first variant java machine implicitly adds those part:
new String[]
So the both ways are allowed.