Search code examples
javaarraysintfinal

Array of ints and the keyword final. [Java]


The below code compiles in Java.

public class App{
  public static void main(String args[]){   
    final int[]array = {1,2,3};
    array[2] = 6; //Why can this value be changed if it is final.
  }
}             

Why when making an array of ints "final", does it not make the values case constant. The array values can still be changed above as seen "array[2]=6".

What is the point of the keyword final being used on an array of ints? Is there any way to make this array of ints case constant.


Solution

  • No. final means your reference is final, not the value.