• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array dimension missing  RSS feed

 
Stephanie Dears
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a line in my code:

int array = new int[] array;

the error is array dimention missing

What does this mean?

Steph
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To declare an array you need something along the lines of

int[] anIntArray = new int[10];

This declares 'anIntArray' to be an array of length 10.
 
Stephanie Dears
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's reading from a .txt file.
 
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
You can declare an array of unknown size like this:

int[] array;

but there's no array object there. You can't use "new" to actually create the object until you actually know the size.

If you don't know the size -- that's what we're talking about here, right? -- then don't use an array: use one of the Collections classes in java.util. For example, java.util.ArrayList, which is rather like an array, but it grows automatically as you add items to it.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!