zoukankan      html  css  js  c++  java
  • java数据结构之列表——ArrayList,LinkedList,比较

    刚看完《数据结构与算法分析java语言描述》的第3章中的表,下面回忆下主要知识点,主要说明各列表之间的关系,以及各自的优缺点。其中牵涉到内部类和嵌套类。

    1 Collection API
    public interface Collection<AnyType> extens Iterable<AnyType>

    {

    int size();

    boolean isEmpty();

    void clear();

    boolean contains(AnyType x);

    boolean add(AnyType x);

    boolean remove(AnyType x);

    java.util.Iterator<AnyType> iteratoe();

    }

    2 Iterator API

    public interface Iterator<AnyType>

    {

    boolean hasNext();

    AnyType next();

    void move();

    }

    3 List

    public interface List<AnyType> extents Collection<AnyType>

    {

    AnyType get(int idx);

    AnyType set (int idx,AnyType newVal);

    void add(int idx,AnyType x);

    void remove(int idx);

    ListIterator<AnyType> listIterator(int pos);

    }

    4 ListIterator

    public interface ListIterator<AnyType> extents Iterator<AnyType>

    {

    boolean hasPrevious();

    AnyType previous();

    void add(AnyType x);

    void set(AnyType newVal);

    }

    5 ArrayList是List的一种可增长的数组实现,优点是get和set花费常数时间,而insert和remove代价昂贵。除非是在末端进行。

    6 LinkedList是List的双链表实现,优点是insert和remove开销较小,而get和set花费较大。不容易操作索引。

    7 iterator的remove方法比LinkedList效率更高,因为迭代器位于需要被删除的节点附近。但是使用iterato时,list的结构不能被改变(例如insert,remove等)。

    8 嵌套内常常用static放在类内部,其无法确定引用的主体;而内部类无需static声明,并且可自动确定引用的主体为其外部类。

  • 相关阅读:
    设置 nextjs build 时,忽略 page 目录下相关文件
    Resource Override 之调试线上 js
    nodejs npm 基础命令
    禁止选择或禁止复制网页数据
    对上传的图片进行格式校验以及安全性校验
    docker 设置阿里云镜像加速
    JS 格式化输出时间
    dotnet core 实现 IActionResult
    win10 visual studio 设置默认管理员权限启动
    Windows 环境部署 RabbitMQ
  • 原文地址:https://www.cnblogs.com/MiWang/p/5753966.html
Copyright © 2011-2022 走看看