Java List

    /**
     * Returns the number of elements in this list.  If this list contains
     * more than {@code Integer.MAX_VALUE} elements, returns
     * {@code Integer.MAX_VALUE}.
     *
     * @return the number of elements in this list
     */
    int size();

    /**
     * Returns {@code true} if this list contains no elements.
     *
     * @return {@code true} if this list contains no elements
     */
    boolean isEmpty();

    /**
     * Returns {@code true} if this list contains the specified element.
     * More formally, returns {@code true} if and only if this list contains
     * at least one element {@code e} such that
     * {@code Objects.equals(o, e)}.
     *
     */
    boolean contains(Object o);

    /**
     * Returns an array containing all of the elements in this list in proper
     * sequence (from first to last element).
     *
     *

The returned array will be "safe" in that no references to it are
     * maintained by this list.  (In other words, this method must
     * allocate a new array even if this list is backed by an array).
     * The caller is thus free to modify the returned array.
     *
     *

This method acts as bridge between array-based and collection-based
     * APIs.
     * @see Arrays#asList(Object[])
     */
    Object[] toArray();

    /**
     * Appends the specified element to the end of this list (optional
     * operation).
     */ 控制添加元素的类型等
    boolean add(E e);

    /**
     * Removes the first occurrence of the specified element from this list,
     * if it is present (optional operation).  If this list does not contain
     * the element, it is unchanged.  More formally, removes the element with
     * the lowest index {@code i} such that
     * {@code Objects.equals(o, get(i))}
     */
  boolean remove(Object o);

  /**
     * Appends all of the elements in the specified collection to the end of
     * this list
     */
  boolean addAll(Collection<? extends E> c);

  /**
     * Removes from this list all of its elements that are contained in the
     * specified collection (optional operation).
     */
    boolean removeAll(Collection<?> c);

    /**
     * Removes all of the elements from this list (optional operation).
     * The list will be empty after this call returns.
     *
     * @throws UnsupportedOperationException if the {@code clear} operation
     *         is not supported by this list
     */
    void clear();

判断两个list相等?
    /**
     * Compares the specified object with this list for equality.  Returns
     * {@code true} if and only if the specified object is also a list, both
     * lists have the same size, and all corresponding pairs of elements in
     * the two lists are equal.  (Two elements {@code e1} and
     * {@code e2} are equal if {@code Objects.equals(e1, e2)}.)
     * In other words, two lists are defined to be
     * equal if they contain the same elements in the same order.  This
     * definition ensures that the equals method works properly across
     * different implementations of the {@code List} interface.
     *
     * @param o the object to be compared for equality with this list
     * @return {@code true} if the specified object is equal to this list
     */
    boolean equals(Object o);
        ArrayList arr1 = new ArrayList();
        ArrayList arr2 = new ArrayList();

        arr1.add("仅仅是");
        arr1.add("其中值");
        arr1.add("的顺序");
        arr1.add("不相同");
        //
        arr2.add("其中值");
        arr2.add("不相同");
        arr2.add("仅仅是");
        arr2.add("的顺序");
        
        Collections.sort(arr1);
        Collections.sort(arr2);
        
        if(arr1.equals(arr2)){
            System.out.println("相同的");
        }
import java.util.ArrayList;
public class X {
 public static void main(String[] args) {
  ArrayList a=new ArrayList();
  a.add(1);
  a.add(2);
  a.add(3);
  ArrayList b=new ArrayList();
  b.add(1);
  b.add(2);
  b.add(3);
  System.out.println(a.equals(b));
 }
}

10         /* 第二种遍历方式 */
11         System.out.print("foreach的遍历方式:");
12         for (Integer list : lists) {
13             System.out.print(list);
14         }
    get/set/indexOf
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值