---
title: "number.length-1 in an array, what does the “-1” stands for"  
description: "number.length-1 in an array, what does the “-1” stands for"  
author: "Anonymous User"  
published: 2013-10-05  
updated: 2013-10-05  
canonical: https://www.mindstick.com/forum/1601/number-length-1-in-an-array-what-does-the-1-stands-for  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# number.length-1 in an array, what does the “-1” stands for

I am new to Java. I got this from a [website](https://www.mindstick.com/articles/13110/why-copywriting-is-crucial-for-new-website-build) and it does bubblesort. I doubt why is there "-1" after the "number.length". I just don't quite get it. Grateful if [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) could help.

```
import java.util.Arrays;public class Bubblesort {  public static void main(String[] args) {    int[] number = {5,16,4,32,30};    int j;    boolean flag = true;   // set flag to true to begin first pass    int temp;   //holding variable    while ( flag )    {          flag= false;    //set flag to false awaiting a possible swap          for( j=0;  j <number.length-1;  j++ )          {                 if ( number[ j ] > number[j+1] )   // change to > for ascending sort                 {                         temp = number[ j ];                //swap elements                         number[ j ] = number[ j+1 ];                         number[ j+1 ] = temp;                        flag = true;              //shows a swap occurred                }          }    }    System.out.println(Arrays.toString( number ));  }}
```

## Replies

### Reply by Anonymous User

You need to remove 1 from the length of an array to get the last element because arrays are 0-based, but the length is 1-based.


---

Original Source: https://www.mindstick.com/forum/1601/number-length-1-in-an-array-what-does-the-1-stands-for

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
