zoukankan      html  css  js  c++  java
  • 集合

    package day35;

    import java.util.ArrayList;
    import java.util.Collection;

    /*
    接口 Collection
    所有集合的都实现接口;
    常用方法
    boolean add(E e) 添加元素。
    void clear()移除此 collection 中的所有元素
    boolean contains(Object o)如果此 collection 包含指定的元素,则返回 true。
    boolean isEmpty()判断集合是否为空;
    boolean remove(Object o)从此 collection 中移除指定元素的单个实例,如果存在的话(可选操作)。
    int size()返回此 collection 中的元素数。
    Object[] toArray()返回包含此 collection 中所有元素的数组。
    */
    public class list {
    public static void main(String[] args) {
    ArrayList str=new ArrayList<>();
    str.add("胡澳宾");
    str.add("李易峰");
    str.add("彭于晏");
    str.add("王建民");
    System.out.println(str);
    str.remove("胡澳宾");
    System.out.println(str);
    System.out.println(str.contains("胡澳宾"));
    System.out.println(str.isEmpty());
    System.out.println(str.size());
    Object []s=str.toArray();
    for (int i = 0; i <str.size() ; i++) {
    System.out.println(s[i]);
    }
    str.clear();
    System.out.println(str);
    }
    }
  • 相关阅读:
    Netty应用
    原生JDK网络编程- NIO之Reactor模式
    Kafka入门教程
    Java CAS
    Java读写锁
    遍历map的四种方法
    java selector
    Range Sum Query
    Increasing Triplet Subsequence
    Count Numbers with Unique Digits
  • 原文地址:https://www.cnblogs.com/huaobin/p/13817178.html
Copyright © 2011-2022 走看看