• Post Reply Bookmark Topic Watch Topic
  • New Topic

How determine size of table?  RSS feed

 
Andrzej Borucki
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can be :
results = null;
results = new double[2];
results = new double[50];
results = new double[100];

How determine size of this table : System.out.println("table size=",???);
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is in this tutorial.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be aware of null array reference. It does not mean array of size 0. It means no array at all. Trying to get length of null reference will throw NullPointerException.
 
Andrzej Borucki
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Virtual machine knows array size since throw exception. But programmer can't know?
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrzej Borucki wrote:Virtual machine knows array size since throw exception. But programmer can't know?

Did you read the tutorial Stevens posted? The answer is there.
 
Andrzej Borucki
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't found in this article about functions like length() or high()
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read again then.

Finally, you can use the built-in length property to determine the size of any array. The following code prints the array's size to standard output:
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Read again then.

Finally, you can use the built-in length property to determine the size of any array. The following code prints the array's size to standard output:

Yup, that's it. Note that length is a property of an array, not a method. That is, you use
and not

That's kind of a departure from the teaching that all properties should be manipulated by accessor and mutator methods (getters and setters, mostly), but we just have to live with it.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!