• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array declaration

 
roshni bhagat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this declaration correct:
int[] arr = new int[5][];
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it isn't.

The declared type is int[] - array of integers.
The initialized type is int[][] - array of array of integers.

So either add a [] in the declaration, or remove the [] (keep the [5]) in the initialization.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Doesn't your compiler tell you this?


creates a variable which references a one dimensional array of primitive integers.


creates a two dimensional array of primitive integers.

You can't assign one to the other.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic