从源码刨析java底层API

java.util.Arrays

//可以传入很多基础类型
public static void sort(int[] a) {    }
public static void sort(int[] a, int fromIndex, int toIndex) {
        rangeCheck(a.length, fromIndex, toIndex);
        DualPivotQuicksort.sort(a, fromIndex, toIndex - 1, null, 0, 0);
    }
    //parallel并行
public static void parallelSort(byte[] a) { }
//传入比较器,可以使用lamda表达式
//(o1,o2)->{return o2-o1;}
public static <T> void parallelSort(T[] a, Comparator<? super T> cmp) {}
public static <T> void sort(T[] a, Comparator<? super T> c)
public static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
//使用提供的函数并行地累计给定数组中的每个元素。例如,如果数组最初保存[2,1,0,3],操作执行加法,那么返回时数组保存[2,3,3,6]。对于大型数组,并行前缀计算通常比顺序循环更高效。
public static <T> void parallelPrefix(T[] array, BinaryOperator<T> op) {    }
public static <T> void parallelPrefix(T[] array, int fromIndex,
                                          int toIndex, BinaryOperator<T> op) 

//使用二分查找算法在指定的long数组中查找指定的值。调用之前,数组必须是有序的(就像sort(long[])方法那样)。如果没有排序,结果是未定义的。如果数组包含多个具有指定值的元素,则不能保证找到哪一个。
 public static int binarySearch(long[] a, long key) {
        return binarySearch0(a, 0, a.length, key);
    }
public static int binarySearch(long[] a, int fromIndex, int toIndex,
                                   long key)
//如果两个指定的long数组相等,则返回true。如果两个数组包含相同数量的元素,且两个数组中所有对应的元素对都相等,则认为两个数组相等。换句话说,如果两个数组以相同的顺序包含相同的元素,则两个数组相等。另外,如果两个数组引用都为null,则认为它们相等。
public static boolean equals(long[] a, long[] a2)
//Assigns the specified int value to each element of the specified array of ints.
public static void fill(int[] a, int val) {
        for (int i = 0, len = a.length; i < len; i++)
            a[i] = val;
    }
//复制指定的数组,在必要时用null截断或填充,使复制的数组具有指定的长度。对于在原始数组和副本中都有效的所有下标,两个数组将包含相同的值。对于任何在副本中有效但在原始索引中无效的索引,副本将包含null。当且仅当指定的长度大于原始数组的长度时,这样的索引才会存在。得到的数组和原始数组属于同一类。
public static <T> T[] copyOf(T[] original, int newLength) {
        return (T[]) copyOf(original, newLength, original.getClass());
    }
//得到的数组类型是newType。
public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType) {

//将指定数组的指定范围复制到新数组中。
public static <T> T[] copyOfRange(T[] original, int from, int to) {
        return copyOfRange(original, from, to, (Class<? extends T[]>) original.getClass());
    }
public static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
//返回由指定数组支持的固定大小的列表。
public static <T> List<T> asList(T... a) {
        return new ArrayList<>(a);
    }
//如果两个指定数组深度相等,则返回true。与equals(Object[], Object[])方法不同,这个方法适合用于任意深度的嵌套数组。
public static boolean deepEquals(Object[] a1, Object[] a2)

//返回指定数组内容的字符串表示形式。字符串表示由数组元素的列表组成,括在方括号("[]")中。相邻的元素由字符“,”(逗号后接一个空格)分隔。使用String.valueOf(long)将元素转换为字符串。如果a为null,则返回"null"。
public static String toString(int[] a)


//返回指定数组的“深层内容”的字符串表示形式。如果数组包含其他数组作为元素,则字符串表示包含它们的内容,以此类推。这个方法用于将多维数组转换为字符串。

private static class ArrayList<E> extends AbstractList<E>
        implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
        private final E[] a;

        ArrayList(E[] array) {
            a = Objects.requireNonNull(array);
        }

        @Override
        public int size() {
            return a.length;
        }

        @Override
        public Object[] toArray() {
            return a.clone();
        }

        @Override
        @SuppressWarnings("unchecked")
        public <T> T[] toArray(T[] a) {
            int size = size();
            if (a.length < size)
                return Arrays.copyOf(this.a, size,
                                     (Class<? extends T[]>) a.getClass());
            System.arraycopy(this.a, 0, a, 0, size);
            if (a.length > size)
                a[size] = null;
            return a;
        }

        @Override
        public E get(int index) {
            return a[index];
        }

        @Override
        public E set(int index, E element) {
            E oldValue = a[index];
            a[index] = element;
            return oldValue;
        }

        @Override
        public int indexOf(Object o) {
            E[] a = this.a;
            if (o == null) {
                for (int i = 0; i < a.length; i++)
                    if (a[i] == null)
                        return i;
            } else {
                for (int i = 0; i < a.length; i++)
                    if (o.equals(a[i]))
                        return i;
            }
            return -1;
        }

        @Override
        public boolean contains(Object o) {
            return indexOf(o) != -1;
        }

        @Override
        public Spliterator<E> spliterator() {
            return Spliterators.spliterator(a, Spliterator.ORDERED);
        }

        @Override
        public void forEach(Consumer<? super E> action) {
            Objects.requireNonNull(action);
            for (E e : a) {
                action.accept(e);
            }
        }

        @Override
        public void replaceAll(UnaryOperator<E> operator) {
            Objects.requireNonNull(operator);
            E[] a = this.a;
            for (int i = 0; i < a.length; i++) {
                a[i] = operator.apply(a[i]);
            }
        }

        @Override
        public void sort(Comparator<? super E> c) {
            Arrays.sort(a, c);
        }
    }

java.util.ArrayList

public class ArrayList<E> extends AbstractList<E>
        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
{
public int size() 
//Returns true if this list contains no elements
 public boolean isEmpty() {
        return size == 0;
    }
//如果列表中包含指定元素,则返回true。更正式地说,当且仅当列表中包含至少一个元素e且满足(o==null ?e = = null: o.equals (e))
 public boolean contains(Object o) {
        return indexOf(o) >= 0;
    }
//返回指定元素在此列表中第一次出现的索引,如果列表中不包含该元素,则返回-1。更正式地说,返回最小的索引i (o==null ?Get (i)==null: o.equals(Get (i))),如果没有索引,则为-1
    public int indexOf(Object o)
//返回指定元素在此列表中最后一次出现的索引,如果列表中不包含该元素,则返回-1。更正式地说,返回最大的索引i (o==null ?Get (i)==null: o.equals(Get (i))),如果没有索引,则为-1。
public int lastIndexOf(Object o)
//返回这个ArrayList实例的浅拷贝。(元素本身不会被复制。)
public Object clone() 
//以正确的顺序(从第一个元素到最后一个元素)返回包含此列表中所有元素的数组。返回的数组是“安全的”,因为这个列表没有维护对它的引用。(换句话说,这个方法必须分配一个新数组)。因此,调用者可以自由地修改返回的数组。
public Object[] toArray() {
        return Arrays.copyOf(elementData, size);
    }
//按正确的顺序(从第一个元素到最后一个元素)返回一个包含该列表中所有元素的数组;返回数组的运行时类型是指定数组的运行时类型。如果列表能放到指定的数组中,则将其返回到数组中。否则,将使用指定数组的运行时类型和此列表的大小分配一个新数组。如果列表可以容纳到指定数组中(即数组的元素比列表多),则将集合末尾的元素设置为null。(只有在调用者知道链表不包含任何null元素时,这才能确定链表的长度。)
public <T> T[] toArray(T[] a)

//Returns the element at the specified position in this list.返回列表中指定位置的元素。
    public E get(int index) {
        rangeCheck(index);

        return elementData(index);
    }
//用指定的元素替换列表中指定位置的元素。
public E set(int index, E element) {
        rangeCheck(index);

        E oldValue = elementData(index);
        elementData[index] = element;
        return oldValue;
    }
//将指定的元素附加到列表的末尾。
 public boolean add(E e) {
        ensureCapacityInternal(size + 1);  // Increments modCount!!
        elementData[size++] = e;
        return true;
    }
//将指定的元素插入到列表中的指定位置。将当前位置(如果有)的元素以及后续的元素向右移动(在其下标上加1)。
public void add(int index, E element) {
        rangeCheckForAdd(index);

        ensureCapacityInternal(size + 1);  // Increments modCount!!
        System.arraycopy(elementData, index, elementData, index + 1,
                         size - index);
        elementData[index] = element;
        size++;
    }
//删除列表中指定位置的元素。将后续元素向左移动(下标减1)。
public E remove(int index) {

//如果指定的元素存在,则从列表中删除它的第一个匹配项。如果链表不包含该元素,则链表不会改变。更正式地说,删除索引为i的最小元素(o==null ?Get (i)==null: o.c oequals (Get (i)))(如果存在这样的元素)如果列表中包含指定的元素(或者同样地,如果列表因调用而改变),返回true。
public boolean remove(Object o) 
//从列表中删除所有元素。这个列表在调用返回后将为空。
public void clear() {
        modCount++;

        // clear to let GC do its work
        for (int i = 0; i < size; i++)
            elementData[i] = null;

        size = 0;
    }
 
//按照指定集合的迭代器返回的顺序,将指定集合中的所有元素追加到列表的末尾。如果在操作过程中修改了指定的集合,则此操作的行为是未定义的。(这意味着如果指定的集合是这个列表,并且这个列表非空,那么这个调用的行为是未定义的。)
public boolean addAll(Collection<? extends E> c)
public boolean addAll(int index, Collection<? extends E> c)

//从列表中删除索引介于fromIndex (inclusive)和toIndex (exclusive)之间的所有元素。将后续元素向左移动(降低索引)。这个调用通过(toIndex - fromIndex)元素缩短列表。(如果toIndex==fromIndex,则此操作无效。)
protected void removeRange(int fromIndex, int toIndex)

//从列表中删除包含在指定集合中的所有元素。
public boolean removeAll(Collection<?> c) {
        Objects.requireNonNull(c);
        return batchRemove(c, false);
    }
//仅保留此列表中包含在指定集合中的元素。换句话说,从列表中删除不在指定集合中的所有元素。
 public boolean retainAll(Collection<?> c) {
        Objects.requireNonNull(c);
        return batchRemove(c, true);
    }

//返回一个列表迭代器,遍历列表中的元素(按正确的顺序),从列表中的指定位置开始。指定的索引表示首次调用next将返回的第一个元素。第一次调用previous将返回指定索引减1的元素。
 public ListIterator<E> listIterator(int index) {
        if (index < 0 || index > size)
            throw new IndexOutOfBoundsException("Index: "+index);
        return new ListItr(index);
    }
  public ListIterator<E> listIterator() {
        return new ListItr(0);
    }
//以正确的顺序返回列表中元素的迭代器。
public Iterator<E> iterator() {
        return new Itr();
    }

}

java.util.HashSet

//Returns the number of elements in this set (its cardinality)
public int size() {
        return map.size();
    }
//Returns true if this set contains no elements.
 public boolean isEmpty() {
        return map.isEmpty();
    }
//如果此集合包含指定的元素,则返回true。更正式地说,当且仅当集合中包含元素e且满足(o==null ?e = = null: o.equals (e))。
 public boolean contains(Object o) {
        return map.containsKey(o);
    }
//如果指定的元素不存在,则将其添加到此集合中。更正式地说,如果这个集合不包含元素e2,则将指定的元素e添加到这个集合中,如下(e==null ?e2 = = null: e.equals (e2))。如果集合中已经包含了元素,则不改变集合并返回false。
public boolean add(E e) {
        return map.put(e, PRESENT)==null;
    }
 //如果指定元素存在,则从集合中删除该元素。更正式地说,删除元素e,如下(o==null ?E ==null: o.c oequals (E)),如果集合中包含这样的元素。如果集合中包含元素(或者同样地,如果集合因调用而改变),返回true。(一旦调用返回,这个集合将不再包含元素。)
 public boolean remove(Object o) {
        return map.remove(o)==PRESENT;
    }
//Removes all of the elements from this set. The set will be empty after this call returns.
public void clear() {
        map.clear();
    }
//返回这个HashSet实例的浅副本:元素本身不会被复制。
 public Object clone() 

//将HashSet实例的状态保存到一个流中(也就是序列化它)。
    private void writeObject(java.io.ObjectOutputStream s)
        throws java.io.IOException {
private void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {

java.util.HashMap

//Returns the number of key-value mappings in this map
public int size() {
        return size;
    }
//Returns true if this map contains no key-value mappings.
public boolean isEmpty() {
        return size == 0;
    }

//返回指定键映射到的值,如果此映射不包含该键的映射,则返回null。
//更正式地说,如果这个map包含一个从键k到值v的映射,那么(key==null ?K ==null: key.equals(K)),那么这个方法返回v;否则返回null。(最多只能有一个这样的映射。)
//返回值为null并不一定表示该映射中没有对应的键;map也可能显式地将键映射为null。可以使用containsKey操作来区分这两种情况。
   public V get(Object key) {
        Node<K,V> e;
        return (e = getNode(hash(key), key)) == null ? null : e.value;
    }
 
//获取及其相关方法。
final Node<K,V> getNode(int hash, Object key)
 //如果此映射包含指定键的映射,则返回true。
 public boolean containsKey(Object key) {
        return getNode(hash(key), key) != null;
    }

//在这个映射中将指定的值与指定的键关联。如果map之前包含一个对应键的映射,旧的值会被替换。
public V put(K key, V value) {
        return putVal(hash(key), key, value, false, true);
    }

//Initializes or doubles table size. If null, allocates in accord with initial capacity target held in field threshold. Otherwise, because we are using power-of-two expansion, the elements from each bin must either stay at same index, or move with a power of two offset in the new table.
final Node<K,V>[] resize()


java.util.Stack

//将一个元素压入栈顶。
public E push(E item) {
        addElement(item);

        return item;
    }
//移除栈顶的对象,并将该对象作为函数的值返回。返回值:栈顶的对象(Vector对象的最后一个元素)。
public synchronized E pop() {
        E       obj;
        int     len = size();

        obj = peek();
        removeElementAt(len - 1);

        return obj;
    }
//查看栈顶的对象,但不将其从栈中移除返回值:栈顶的对象(Vector对象的最后一个元素)。
public synchronized E peek() {
        int     len = size();

        if (len == 0)
            throw new EmptyStackException();
        return elementAt(len - 1);
    }
 
 //ests if this stack is empty.
public boolean empty() {
        return size() == 0;
    }
//返回对象在堆栈上基于1的位置。如果对象o是这个栈中的一个元素,这个方法返回离栈顶最近的对象到栈顶的距离;栈中最上面的元素距离为1。方法equals用于将o与栈中的元素进行比较。
 public synchronized int search(Object o) {
        int i = lastIndexOf(o);

        if (i >= 0) {
            return size() - i;
        }
        return -1;
    }


java.util.Queue

//如果可以立即将指定的元素插入队列而不违反容量限制,则在成功时返回true;如果当前没有可用空间,则抛出IllegalStateException异常。
boolean add(E e);
 
//在不违反容量限制的情况下,立即将指定的元素插入到队列中。在使用容量受限的队列时,这种方法通常比add方法更可取,因为add方法可能会抛出异常,导致无法插入元素。
 boolean offer(E e);
 
//Retrieves and removes the head of this queue. This method differs from poll only in that it throws an exception if this queue is empty.
 E remove();

//获取并移除队列头,如果队列为空则返回null。
E poll();

//获取但不删除该队列的头。这个方法与peek的不同之处在于,如果队列为空,它会抛出异常。
E element();
//获取但不删除队列头,如果队列为空则返回null。
    E peek();

java.util.List

//有序集合(也称为序列)。使用该接口的用户可以精确控制每个元素插入到列表中的位置。用户可以通过整数索引(列表中的位置)访问元素,也可以在列表中搜索元素。

//与集合不同,列表通常允许出现重复的元素。更正式的说法是,列表通常允许包含成对的元素e1和e2,如e1.equals(e2);如果列表允许包含null元素,则通常允许包含多个null元素。有人可能希望实现一个禁止重复的列表,通过在用户试图插入它们时抛出运行时异常,这并不是不可想象的,但我们希望这种用法很少出现。

public interface List<E> extends Collection<E> {
//Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
 int size();

//Returns true if this list contains no elements.
boolean isEmpty();

//如果列表中包含指定元素,则返回true。更正式地说,当且仅当列表中包含至少一个元素e且满足(o==null ?e = = null: o.equals (e))。
boolean contains(Object o);
 
//以正确的顺序返回列表中元素的迭代器。
Iterator<E> iterator();

//以正确的顺序(从第一个元素到最后一个元素)返回包含此列表中所有元素的数组。
//返回的数组是“安全的”,因为这个列表没有维护对它的引用。(换句话说,这个方法必须分配一个新数组,即使这个列表的背后是一个数组)。因此,调用者可以自由地修改返回的数组。
//这个方法充当了基于数组的api和基于集合的api之间的桥梁。
Object[] toArray();
 
//将指定元素添加到列表的末尾(可选操作)。
//支持此操作的列表可能会限制哪些元素可以添加到该列表中。具体来说,有些链表拒绝添加null元素,而有些链表会对添加元素的类型有所限制。列表类应该在其文档中明确规定可以添加哪些元素的限制。
boolean add(E e);

//如果指定元素存在,则从列表中删除它的第一个元素(可选操作)。如果该链表不包含该元素,则它不会改变。更正式地说,删除索引为i的最小元素(o==null ?Get (i)==null: o.c oequals (Get (i)))(如果存在这样的元素)如果列表中包含指定的元素(或者同样地,如果列表因调用而改变),返回true。
boolean remove(Object o);

//如果列表包含指定集合的所有元素,则返回true。
boolean containsAll(Collection<?> c);

//按照指定集合的迭代器返回的顺序(可选操作),将指定集合中的所有元素追加到列表的末尾。如果在操作过程中修改了指定的集合,则此操作的行为是未定义的。(注意,如果指定的集合是这个列表且非空,就会发生这种情况。)
 boolean addAll(Collection<? extends E> c);

//将指定集合中的所有元素插入到该列表中的指定位置(可选操作)。将当前位置(如果有)的元素及其后续元素向右移动(增加索引)。新元素将按照指定集合的迭代器返回的顺序出现在这个列表中。如果在操作过程中修改了指定的集合,则此操作的行为是未定义的。(注意,如果指定的集合是这个列表且非空,就会发生这种情况。)
 boolean addAll(int index, Collection<? extends E> c);

//从列表中删除包含在指定集合中的所有元素(可选操作)。
boolean removeAll(Collection<?> c);

//只保留列表中指定集合中包含的元素(可选操作)。换句话说,从列表中删除不在指定集合中的所有元素
boolean retainAll(Collection<?> c);


//根据指定的比较器的顺序对列表进行排序。这个列表中的所有元素都必须使用指定的比较器相互比较(也就是说,c.c ercompare (e1, e2)不能对列表中的任何元素e1和e2抛出ClassCastException异常)。如果指定的比较器为null,那么这个列表中的所有元素都必须实现Comparable接口,并且应该使用元素的自然顺序。这个列表必须是可修改的,但不一定是可调整大小的。
default void sort(Comparator<? super E> c) {
        Object[] a = this.toArray();
        Arrays.sort(a, (Comparator) c);
        ListIterator<E> i = this.listIterator();
        for (Object e : a) {
            i.next();
            i.set((E) e);
        }
    }

//Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
void clear();

//比较指定对象与此列表是否相等。当且仅当指定的对象也是一个列表,两个列表的大小相同,并且两个列表中所有对应的元素对都相等时,返回true(两个元素e1和e2相等,如果(e1==null ?e2 = = null: . equals (e2)))。换句话说,如果两个列表以相同的顺序包含相同的元素,则将它们定义为相等。这个定义确保方法equals可以在List接口的不同实现中正常工作。
boolean equals(Object o);

/**
     * Returns the hash code value for this list.  The hash code of a list
     * is defined to be the result of the following calculation:
     * <pre>{@code
     *     int hashCode = 1;
     *     for (E e : list)
     *         hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
     * }</pre>
     * This ensures that <tt>list1.equals(list2)</tt> implies that
     * <tt>list1.hashCode()==list2.hashCode()</tt> for any two lists,
     * <tt>list1</tt> and <tt>list2</tt>, as required by the general
     * contract of {@link Object#hashCode}.
     *
     * @return the hash code value for this list
     * @see Object#equals(Object)
     * @see #equals(Object)
     */
    int hashCode();

/*
返回列表中指定位置的元素。
形参:
□Index:要返回的元素的索引
返回值:
列表中指定位置的元素
*/
E get(int index);

//用指定的元素替换列表中指定位置的元素(可选操作)。
E set(int index, E element);

//将指定元素插入到列表的指定位置(可选操作)。将当前位置(如果有)的元素以及后续的元素向右移动(在其下标上加1)。
void add(int index, E element);
E remove(int index);

//返回指定元素在此列表中第一次出现的索引,如果列表中不包含该元素,则返回-1。更正式地说,返回最小的索引i (o==null ?Get (i)==null: o.equals(Get (i))),如果没有索引,则为-1。
int indexOf(Object o);

//Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
int lastIndexOf(Object o);

//返回列表元素的列表迭代器(按正确的顺序)。
//返回值:
//一个列表迭代器,遍历列表中的元素(按正确的顺序)。
ListIterator<E> listIterator();
 ListIterator<E> listIterator(int index);


java.util.LinkedList

list和Deque接口的双向链表实现。实现所有可选的列表操作,并允许所有元素(包括null)。

所有的操作都和双向链表的操作一样。对列表进行索引的操作将从起始或结束遍历列表,以更接近指定索引的为准。

请注意,该实现不是同步的。如果多个线程并发访问一个链表,并且其中至少有一个线程在结构上修改了链表,那么链表必须在外部进行同步。(结构修改是指添加或删除一个或多个元素的操作;仅仅设置元素的值并不是结构上的修改。)这通常是通过在封装了列表的对象上进行同步来完成的。如果不存在这样的对象,则应该使用集合“包装”列表。

public class LinkedList<E>
    extends AbstractSequentialList<E>
    implements List<E>, Deque<E>, Cloneable, java.io.Serializable
{

//Returns the first element in this list.
    public E getFirst() {
        final Node<E> f = first;
        if (f == null)
            throw new NoSuchElementException();
        return f.item;
    }

//Returns the last element in this list.
public E getLast() {

//Removes and returns the first element from this list.
  public E removeFirst() {

//Removes and returns the last element from this list.
  public E removeLast() {

//在列表的开头插入指定的元素。
public void addFirst(E e) {
        linkFirst(e);
    }

ublic void addLast(E e) {
        linkLast(e);
    }

//Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)).
   public boolean contains(Object o) {
        return indexOf(o) != -1;
    }

//Returns the number of elements in this list.
  public int size() {
        return size;
    }

//将指定的元素附加到列表的末尾。
//这个方法等价于addLast。
public boolean add(E e) {
        linkLast(e);
        return true;
    }
 
 //如果指定的元素存在,则从列表中删除它的第一个匹配项。如果该链表不包含该元素,则它不会改变。更正式地说,删除索引为i的最小元素(o==null ?Get (i)==null: o.c oequals (Get (i)))(如果存在这样的元素)如果列表中包含指定的元素(或者同样地,如果列表因调用而改变),返回true。
  public boolean remove(Object o) {

    public boolean addAll(Collection<? extends E> c) {
        return addAll(size, c);
    }

 public boolean addAll(int index, Collection<? extends E> c) {
  
//Removes all of the elements from this list. The list will be empty after this call returns.
 public void clear() {

//Returns the element at the specified position in this list.
   public E get(int index) {
        checkElementIndex(index);
        return node(index).item;
    }


//用指定的元素替换列表中指定位置的元素。
public E set(int index, E element) {

//将指定的元素插入到列表中的指定位置将当前位置(如果有)的元素以及后续的元素向右移动(在其下标上加1)。
public void add(int index, E element) {

//Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
public E remove(int index) {
        checkElementIndex(index);
        return unlink(node(index));
    }

//判断参数是否为现有元素的索引
    private boolean isElementIndex(int index) {
        return index >= 0 && index < size;
    }
//判断参数是迭代器或添加操作的有效位置的索引。
private boolean isPositionIndex(int index) {
        return index >= 0 && index <= size;
    }

 //返回指定元素索引处的(非空)节点。
  Node<E> node(int index) {

//返回指定元素在此列表中第一次出现的索引,如果列表中不包含该元素,则返回-1。更正式地说,返回最小的索引i (o==null ?Get (i)==null: o.equals(Get (i))),如果没有索引,则为-1。
    public int indexOf(Object o) {
//Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
public int lastIndexOf(Object o) {

//获取但不删除该列表的头(第一个元素)。
//抛出:
//NoSuchElementException – if this list is empty
public E peek() {
        final Node<E> f = first;
        return (f == null) ? null : f.item;
    }
//Retrieves, but does not remove, the head (first element) of this list.
//the head of this list, or null if this list is empty
public E element() {
        return getFirst();
    }

//Retrieves and removes the head (first element) of this list.
public E poll() {

//Retrieves and removes the head (first element) of this list
public E remove() {
        return removeFirst();
    }

//添加指定的元素作为这个列表的尾部(最后一个元素)。
public boolean offer(E e) {
        return add(e);
    }
//将指定的元素插入到列表的前面。
 public boolean offerFirst(E e) {
        addFirst(e);
        return true;
    }
 public boolean offerLast(E e) {
        addLast(e);
        return true;
    }

//Retrieves, but does not remove, the first element of this list, or returns null if this list is empty.
public E peekFirst() {
public E peekLast() {

//检索并删除列表的第一个元素,如果列表为空,则返回null。

 
public E pollFirst() {
public E pollLast() {

//将一个元素压入由该列表表示的栈。换句话说,将元素插入到列表的前面。
 public void push(E e) {
        addFirst(e);
    }
 //从该列表表示的栈中弹出一个元素。换句话说,删除并返回该列表的第一个元素。
public E pop() {
        return removeFirst();
    }



java/lang/String.java

//将这个字符串与指定的对象进行比较。当且仅当参数不是null且是表示与该对象相同字符序列的String对象时,结果为true。
public boolean equals(Object anObject) {
//将这个字符串与指定的StringBuffer进行比较。当且仅当这个字符串表示的字符序列与指定的StringBuffer相同时,结果为true。这个方法在StringBuffer上同步。
private boolean nonSyncContentEquals(AbstractStringBuilder sb) {

//返回这个字符串的长度。长度等于字符串中Unicode编码单位的数量。
public int length() {
        return value.length;
    }

public boolean isEmpty() {
        return value.length == 0;
    }

//返回指定索引处的字符值。索引的范围是从0到length() - 1。序列的第一个字符值的索引为0,下一个字符值的索引为1,以此类推,与数组索引类似。
public char charAt(int index) {
        if ((index < 0) || (index >= value.length)) {
            throw new StringIndexOutOfBoundsException(index);
        }
        return value[index];
    }


//返回指定索引处的字符(Unicode代码点)。索引指向字符值(Unicode代码单位),范围从0到length()- 1。
//如果在给定索引处指定的字符值在高代理项范围内,后续索引小于此字符串的长度,并且后续索引处的字符值在低代理项范围内,则返回与此代理项对对应的补充代码点。否则,返回给定索引处的char值。
public int codePointAt(int index) {

//将这个字符串中的字符复制到目标字符数组中。
//第一个被复制的字符位于索引srcBegin处;最后一个要复制的字符位于索引srcEnd-1处(因此要复制的字符总数是srcEnd-srcBegin)。这些字符被复制到dst的子数组中,从索引dstBegin开始,到索引dstBegin结束:

dstBegin + (srcEnd-srcBegin) - 1
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {

//返回指定字符在此字符串中第一次出现的索引。如果值为ch的字符出现在这个字符串对象表示的字符序列中,则返回第一个此类字符的索引(以Unicode代码单位)。
public int indexOf(int ch) {
        return indexOf(ch, 0);
    }

//返回一个字符串,该字符串是此字符串的子字符串。子字符串从指定索引处的字符开始,一直延伸到字符串的末尾。
public String substring(int beginIndex) {

//判断这个字符串是否匹配给定的正则表达式。
//调用这个方法的形式为str.matches(regex),结果与表达式完全相同
public boolean matches(String regex) {
        return Pattern.matches(regex, this);
    }

//当且仅当此字符串包含指定的字符值序列时返回true
public boolean contains(CharSequence s) {
        return indexOf(s.toString()) > -1;
    }

//将这个字符串分割为给定正则表达式的匹配项。

这个方法返回的数组包含这个字符串的每个子字符串,子字符串以与给定表达式匹配的另一个子字符串结尾,或者以字符串结尾结尾。这个数组中的子字符串与它们在这个字符串中出现的顺序一致。如果表达式不匹配输入的任何部分,则结果数组只有一个元素,即这个字符串。

如果字符串的开头匹配了正宽度,那么结果数组的开头就会包含一个空的前导子字符串。但是,以零宽度开头的匹配永远不会产生这种空的前导子串。

limit参数控制模式应用的次数,因此会影响结果数组的长度。如果限制n大于零,那么模式最多会被应用n - 1次,数组的长度将不大于n,并且数组的最后一项将包含最后匹配的定界符之外的所有输入。如果n是非正数,则模式将被应用尽可能多的次数,并且数组可以具有任意长度。如果n为零,则模式将被应用尽可能多的次数,数组可以有任何长度,末尾的空字符串将被丢弃。
 public String[] split(String regex, int limit) {
//将这个字符串分割为给定正则表达式的匹配项。

这个方法的工作原理类似于用给定的表达式和一个0为limit的参数调用两个参数的split方法。因此,末尾空字符串不会包含在结果数组中。
public String[] split(String regex) {
        return split(regex, 0);
    }



 

java.long.

构造方法摘要
StringBuilder()
构造一个不带任何字符的字符串生成器,其初始容量为 16 个字符。
StringBuilder(CharSequence seq)
构造一个字符串生成器,它包含与指定的 CharSequence 相同的字符。
StringBuilder(int capacity)
构造一个不带任何字符的字符串生成器,其初始容量由 capacity 参数指定。
StringBuilder(String str)
构造一个字符串生成器,并初始化为指定的字符串内容。

 StringBuilder	replace(int start, int end, String str)
          使用给定 String 中的字符替换此序列的子字符串中的字符。
    @Override
    public StringBuilder reverse() {
        super.reverse();
        return this;
    }
          将此字符序列用其反转形式取代。


@Override
    public String toString() {
        // Create a copy, don't share the array
        return new String(value, 0, count);
    }
 String	toString()
          返回此序列中数据的字符串表示形式。

java/util/PriorityQueue.java

将指定的元素插入到优先队列中。

返回值:

true(Collection.add指定)

抛出:ClassCastException:不能根据优先队列的顺序将指定的元素与当前在优先队列中的元素进行比较

□NullPointerException:指定的元素为null
public boolean add(E e) {
        return offer(e);
    }
将指定的元素插入到优先队列中。

返回值:

true(Queue.offer指定)

抛出:ClassCastException:不能根据优先队列的顺序将指定的元素与当前在优先队列中的元素进行比较

□NullPointerException:指定的元素为null
public boolean offer(E e) {
        if (e == null)
            throw new NullPointerException();
        modCount++;
        int i = size;
        if (i >= queue.length)
            grow(i + 1);
        size = i + 1;
        if (i == 0)
            queue[0] = e;
        else
            siftUp(i, e);
        return true;
    }


@SuppressWarnings("unchecked")
    public E peek() {
        return (size == 0) ? null : (E) queue[0];
    }


从队列中移除指定元素的单个实例(如果存在)。更正式地说,如果队列中包含一个或多个这样的元素,则删除元素e,使o.c oequal (e)等于0。当且仅当队列包含指定的元素时返回true(或等价地,如果队列因调用而改变)

形参:O:要从队列中移除的元素(如果存在)

返回值:

如果调用改变了队列,返回True
   public boolean remove(Object o) {
        int i = indexOf(o);
        if (i == -1)
            return false;
        else {
            removeAt(i);
            return true;
        }
    }

如果队列包含指定的元素,则返回true。更正式地说,当且仅当队列中至少包含一个元素e使o.c oequal (e)满足时,返回true。

形参:

O -要检查的对象是否包含在此队列中

返回值:

如果队列中包含指定的元素,返回True
public boolean contains(Object o) {
        return indexOf(o) != -1;
    }


Returns an array containing all of the elements in this queue. The elements are in no particular order.
The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
public Object[] toArray() {
        return Arrays.copyOf(queue, size);
    }

返回用于对队列中的元素排序的比较器,如果队列按照其元素的自然顺序排序,则返回null。

返回值:

用于对队列排序的比较器,如果队列按照元素的自然顺序排序,则为null
  public Comparator<? super E> comparator() {
        return comparator;
    }

 










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值