Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array  RSS feed

 
Pooja Kodali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can the word "array" be used as an array name ?

for eg : int[] array; array = int[2];

is the example above valid ?
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poojitha Kanagala wrote:Can the word "array" be used as an array name ?
Yes - array is not a keyword.

Poojitha Kanagala wrote:for eg : int[] array; array = int[2];

is the example above valid ?
No - you are missing the new operator when creating the array
 
Pooja Kodali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this valid then?

int[] array n= new int[2];
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poojitha Kanagala wrote:Is this valid then?

int[] array n= new int[2];

No, but this would be valid:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!