What is the Java notation for height in a 2D array?

Click For Summary
SUMMARY

The notation for accessing the height of a 2D array in Java is achieved through the expression "math[0].length". In a 2D array such as "math[][]", "math.length" returns the number of rows, while "math[0].length" provides the number of columns. For example, in a 12x15 array, "math.length" yields 12, and "math[0].length" yields 15. This distinction is crucial for understanding the structure of 2D arrays in Java.

PREREQUISITES
  • Understanding of Java array syntax
  • Familiarity with 2D array structures
  • Basic knowledge of Java programming concepts
  • Experience with array indexing in Java
NEXT STEPS
  • Explore Java array manipulation techniques
  • Learn about multidimensional arrays in Java
  • Investigate Java's ArrayList for dynamic array handling
  • Study Java's memory management for arrays
USEFUL FOR

Java developers, computer science students, and anyone looking to deepen their understanding of array structures in Java programming.

UrbanXrisis
Messages
1,192
Reaction score
1
I know that in an array called math[][], the "math.length" will give me the length, or "width" of the array. What is the notation for the "height"?

Ex, if math[][] was a 12x15 array, then math.length=12. how would I get the # 15?
 
Physics news on Phys.org
I'm not sure there is a method for that. Since you know that you have 12 one-dimensional arrays of length 15, I think you could store one of those arrays in another 1D array and then apply myArray.length to get the 15.
 


The notation for the "height" in a 2D array in Java is simply the length of the second dimension. In your example, the "height" would be accessed by using math[0].length, which would return the value 15. This is because the first dimension represents the rows and the second dimension represents the columns in a 2D array. Therefore, to get the "height" of the array, you would need to access the length of the second dimension.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
11
Views
1K