• LinkedList的几个元素操作方法


    看完这几个方法的源码,大概我们知道了,LinkedList不仅实现了队列先进先出 (使用 addremove )也实现了栈的 先进后出 (使用poppush)

    • remove 移除头部元素 Retrieves and removes the head (first element) of this list. @throws NoSuchElementException if this list is empty
    public E remove() {
            return removeFirst();
        }
    
    • poll 移除头部元素 空队列返回null Retrieves and removes the head (first element) of this list.
    public E poll() {
            final Node<E> f = first;
            return (f == null) ? null : unlinkFirst(f);
        }
    
    • pop 栈顶取出 也就是从队列最前面取出 Pops an element from the stack represented by this list. In other words, removes and returns the first element of this list.@throws NoSuchElementException if this list is empty
    public E pop() {
            return removeFirst();
        }
    
     public E removeFirst() {
            final Node<E> f = first;
            if (f == null)
                throw new NoSuchElementException();
            return unlinkFirst(f);
        }
    
    • add 在队列最末尾添加Inserts the specified element at the specified position in this list.
    public boolean add(E e) {
            linkLast(e);
            return true;
        }
    
    • push 压如栈顶。也就是队列最前面插入 Pushes an element onto the stack represented by this list. In other words, inserts the element at the front of this list.
    public void push(E e) {
            addFirst(e);
        }
    
  • 相关阅读:
    T-SQL 查询数据库中各个表的使用空间
    T-SQL 拆分使用指定分隔符的字符串(split string)
    T-SQL 去除特定字段的前导0
    T-SQL 实现行转列
    T-SQL 将存储过程结果插入到表中
    T-SQL查看数据库恢复(RESTORE)时间
    Why Do We Need a Data Warehouse?
    T-SQL 常用DDL语句
    dedecms织梦笔记
    Lua 基础简明教程
  • 原文地址:https://www.cnblogs.com/mxjhaima/p/13942839.html
Copyright © 2020-2023  润新知