-3

What is difference between writing below two?

int[] array = new int[] {1,2,3,4,5,6};

and

int[] array =  {1,2,3,4,5,6}; 
2
  • There's no difference. It's just syntactic sugar. Commented Apr 12, 2018 at 14:42
  • Here you go: The actual definition. Read on. Commented Apr 12, 2018 at 14:44

2 Answers 2

0

Method - 1: declaration, instantiation and initialization int[] array = {1,2,3,4,5,6};

Method - 2: declaration, explicit instantiation and initialization int[] array = new int[] {1,2,3,4,5,6};

Prefered when what to use like display(new int[] {1,2,3,4,5,6}); and this will not work for Method - 1 display({1,2,3,4,5,6});

Sign up to request clarification or add additional context in comments.

Comments

0

There's no difference between this two in term of execution/compilation. The only difference is if you find one more readable than the other then use it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.