Question about java array constants.

Asked 2 years ago, Updated 2 years ago, 165 views

When declaring an array

final int[] arr = {1, 2, 3, 4, 5};

If I do this, I can't just change the address value of the arr, but I can change the arrangement contents, right?

I want to constant the array itself here.

arr[1] = 11;

If I do it like this, I want to make it so that I can't change it because it's a constant.

How do I implement it with the basic syntax provided by java?

java final static array

2022-09-22 18:12

1 Answers

I'd like you to remember one thing

Do not use array in Java as much as possible.

The reason for this is poor scalability and poor code maintenance.

I'm going to go through the main gate...First of all, there is no solution to Java grammar.

The collections class contains a method to create an unchangeable list.

The LIST objects created below are non-changeable.

java.util.Collections.unmodifiableList(Arrays.asLIst(1, 2, 3));


2022-09-22 18:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.