从AbstractList中创建只读的List
package collection;
import java.util.AbstractList;
public class CountingIntegerList extends AbstractList<Integer>{
private int size;
public CountingIntegerList(int size){
this.size = size <0 ? 0 : size;
}
public Integer get(int index) {
return Integer.valueOf(index);
}
public int size() {
return size;
}
public static void main(String[] args) {
System.out.println(new CountingIntegerList(30));
}
}
输出:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
有谁能为我解释一下,为什么会有这样的输出。
import java.util.AbstractList;
public class CountingIntegerList extends AbstractList<Integer>{
private int size;
public CountingIntegerList(int size){
this.size = size <0 ? 0 : size;
}
public Integer get(int index) {
return Integer.valueOf(index);
}
public int size() {
return size;
}
public static void main(String[] args) {
System.out.println(new CountingIntegerList(30));
}
}
输出:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
有谁能为我解释一下,为什么会有这样的输出。
...全文
相关推荐
java集合中的list详解
主要介绍了java集合中的list详解,还是比较不错的,这里分享给大家,需要的朋友可以参考下。
Java基础学习总结(129)——Arrays.asList得到的List进行add和remove等操作出现异常解析
将一个Array的对象转化为List。常常使用Arrays.asList()这个方法,如下单元测试案例: @Test public void testArraysAsList() { List&lt;Integer&gt; list = Arrays.asList(1,2,3,4,5); // list.add(8); assertThat(list, hasItem...
Java中ArrayList类的用法.docx
Java中ArrayList类的用法.docx
UnsupportedOperationException(解决方案).md
UnsupportedOperationException(解决方案).md
java ArrayList的使用与分析
java的 ArrayList的使用与分析


