java定义list长度,在Java中定义固定大小的列表
Is it possible to define a list with a fixed size that's 100? If not why isn't this available in Java?
解決方案
Yes,
Commons library provides a built-in FixedSizeList which does not support the add, remove and clear methods (but the set method is allowed because it does not modify the List's size). In other words, if you try to call one of these methods, your list still retain the same size.
To create your fixed size list, just call
List fixed = FixedSizeList.decorate(Arrays.asList(new YourType[100]));
You can use unmodifiableList if you want an unmodifiable view of the specified list, or read-only access to internal lists.
List unmodifiable = java.util.Collections.unmodifiableList(internalList);
總結(jié)
以上是生活随笔為你收集整理的java定义list长度,在Java中定义固定大小的列表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 众泰芝麻e30可以用公共充电桩吗?
- 下一篇: java oracle数据库高效分页查询