Difference Between arr.length, arr[0].length and arr[1].length in Java17 Mar 2025 | 2 min read Java provides an attribute length that determines the length of an array. Every array has an in-built length property whose value is the size of the array. Size implies the total number of elements that an array can contain. The length property can be invoked by using the dot (.) operator followed by the array name. In this section, we will discuss what is the difference between array.length, array[0].length, and array[1].length. array.length, array[0].length, and array[1].length usually used in the block array (more than one dimensional array). Each dimension has a length. For example, consider the following array. ![]() The above array represents the tabular format of a block array that consists of 50 rows and 70 columns. Suppose, we are required to get the value of the index array[1][4], the value at the index is 30. array[0] refers to the 0th row of the block array. While array[0].length refers to the columns associated with 0th row i.e. 70. Therefore, the answer would be 70. array.length: The length property is used to find the array length. array[0].length: The number of columns on row 0. array[1].length: The number of columns on row 1. In Java, Arrays are objects but not really looks like object. Because, Java allows us to use the index operator (i.e., using brackets[ ]). As Arrays are objects, there are methods and instance variables. In particular, Arrays have a public instance variable called length. It determines the length of the array. Normally, we should avoid using public instance variables to improve encapsulation. However, Java arrays use them, so we must use them as well. Here's how to print a Java array using the length instance variable. Consider the following code snippet. In the above-defined array, the length is 5. Let's understand the concept of array.length, array[0].length, and array[1].length through a Java program. MatrixDemo.java Output: 3 4 4 In the above program, we observe that mat.length is the total number of rows. mat[0].length is the number of columns in 0th row. mat[1].length should have the same value as mat[0].length. Therefore, it has the same number of columns as the first row. Next TopicFuture in Java 8 |
Static Function in Java
In Java, the static keyword can be used with variable, constant, and functions. The main purpose of using the static keyword is to manage the memory so that we can use the memory efficiently. In this section, we will discuss the static function in Java. Static Function If...
3 min read
Generate Binary Numbers 1 to n in Java
Given a number n, generate and print all binary numbers between 1 and n. Example Input: n = 5 Output: 1 10 11 100 101 Explanation: Binary representation of numbers from 1 to 5: 1 1 2 10 3 11 4 100 5 101 Approach 1: Using Built-in Method...
4 min read
Tree Boundary Traversal in Java
Tree Boundary Traversal is a specialized technique in binary tree traversal where nodes are visited in a specific order to cover the outer boundary of the tree. In this traversal, we aim to visit nodes that lie on the periphery of the tree, including the left...
15 min read
ArgoUML Reverse Engineering Java
Reverse engineering is a critical process in software development that allows developers to gain valuable insights into existing codebases. It enables them to understand complex systems, identify design patterns, and improve maintainability. One powerful tool in the arsenal of reverse engineering is ArgoUML, a popular open-source...
3 min read
Process vs. Thread in Java
Regarding concurrent programming in Java, there are two options for executing many tasks simultaneously: processes and threads. While they both provide comparable advantages, there are some significant distinctions between them. Here's a table that compares Java processes and threads: Process Thread A self-contained program that runs in its memory...
4 min read
Dijkstra Algorithm Java
Dijkstra algorithm is one of the prominent algorithms to find the shortest path from the source node to a destination node. It uses the greedy approach to find the shortest path. The concept of the Dijkstra algorithm is to find the shortest distance (path) starting from...
8 min read
Version Enhancements in Exception Handling introduced in Java SE 7
Java SE 7 introduced major improvements to how errors are handled, bringing in features that make error management in Java applications simpler and more efficient. These changes aimed to improve code readability, decrease repetitive code (boilerplate), and enhance the overall experience for developers. The evolution of exception...
7 min read
Reminder Program in Java
In today's fast-paced world, staying organized and keeping track of important tasks and events is crucial. A reminder program can be a handy tool to help manage our busy schedules effectively. In this section, we will explore how to develop a reminder program in Java. We'll...
6 min read
Keytool Error java.io.FileNotFoundException
The Java Keytool is a crucial utility in the Java Development Kit (JDK) that enables developers to manage cryptographic keys, certificates, and key stores. While using Keytool, developers may encounter various exceptions, one of which is the "keytool error: java.io.FileNotFoundException" exception. In this section, we will...
4 min read
Online Java Compiler
An online compiler is a cloud-based IDE that helps the developer to compile and execute a Java program online without installing the JDK in the local system. In this section, we will discuss some popular online Java compilers that are available free of cost. The popular online...
6 min read
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
![arr.length, arr[0].length and arr[1].length in Java](https://images.tpointtech.com/core/images/arr-length-vs-arr-0-length-vs-arr-1-length-in-java.png)