容器

    xiaoxiao2022-07-06  215

    这几天我学习了JAVA有关于容器的知识,知道了三种常见的list实现方法,分别是ArrayList,LinkerList和Vectoir。他们分别得好处是查询效率高,增删效率高,还有线程安全。 目前我已经学习了ArrayList的使用,它主要是对于数组进行了优化,将很多数组的操作进行了重定义,可以增加泛型,同时可以扩容。

    Object[] elementData=new Object[10 ];

    现在开始学习LinkedList, 我突然感觉到StringBuider这个类非常重要,因为每次需要打印有关List的数据时都需要使用这一个类

    public String toString() { StringBuilder sb = new StringBuilder("["); Node temp = first; while(temp!=null){ sb.append(temp.element+","); temp = temp.next; } sb.setCharAt(sb.length()-1, ']'); return sb.toString(); }

    在弄到超出索引范围的数据时需要使用到抛出异常

    throw new RuntimeExcption(" xxx不合法 ")
    最新回复(0)