• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays - JLS  RSS feed

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

While reading about arrays in JLS, found this --


Here are some examples of declarations of array variables that create array objects:

Exception ae[] = new Exception[3];
Object aao[][] = new Exception[2][3];
int[] factorial = { 1, 1, 2, 6, 24, 120, 720, 5040 };
char ac[] = { 'n', 'o', 't', ' ', 'a', ' ',
'S', 't', 'r', 'i', 'n', 'g' };
String[] aas = { "array", "of", "String", };



How do these --


int[] factorial = { 1, 1, 2, 6, 24, 120, 720, 5040 };
char ac[] = { 'n', 'o', 't', ' ', 'a', ' ', 'S', 't', 'r', 'i', 'n', 'g' };


create array objects ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you've seen the syntax

int[] x;
...
x = new int[] { 1, 2, 3 };

right? The syntax

int[] x = { 1, 2, 3};

is just a shortcut for that, allowed only when the variable is being declared.
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.. of course.. what was I thinking
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!