Java学习Day08

2019-09-26  本文已影响0人  JayMeWangGL

今日学习内容总结


Collection集合

        Collection<Integer> collection= new ArrayList<>();
        collection.add(1564);
collection.clear();
collection.remove(1564);
System.out.println(collection.contains(1564));
System.out.println(collection.isEmpty());
System.out.println(collection.size());
Object[] array = collection.toArray();

Iterator迭代器

Iterator是一个接口,无法直接使用。Collection中有个iterator返回一个迭代器

        for (int a:collection ) {
            System.out.println(a);
        }

泛型

public class Person<E> {
    private E name;

    public Person() {
    }

    public Person(E name) {
        this.name = name;
    }

    public E getName() {
        return name;
    }

    public void setName(E name) {
        this.name = name;
    }

}
上一篇下一篇

猜你喜欢

热点阅读