make ArrayList Read only

后端 未结 4 1673
温柔的废话
温柔的废话 2020-12-05 09:30

In Java, how can you make an ArrayList read-only (so that no one can add elements, edit, or delete elements) after initialization?

4条回答
  •  长情又很酷
    2020-12-05 10:01

    Are you sure you want to use an ArrayList in this case?

    Maybe it would be better to first populate an ArrayList with all of your information, and then convert the ArrayList into a final array when the Java program initializes.

提交回复
热议问题