Calendar类:日历类
- 获取对象:public static Calendar get instance()
- 方法:
- public int get(int field)
- public void set(int field)
- public abstract void add(int field, int amount)
- public Date getTime()
Collection集合接口
- public boolean add(E e)
- public boolean addAll(collection <? Extends E> c)
- public void clear()
- public boolean contains(Object o)
- public boolean remove(Object o)
- public int size()
- public object[] toArray()
- public Iterator<E> iterator()
List
- public E get(int index)
- public E set(int index,E element)
- forEach()
ArrayList
- ArrayList 保存自定义对象,为了保证集合contains() 和 remove() 正常执行,必须重写equals()方法
泛型:定义类 或 方法时为了统一数据类型而设定的
注意: 泛型只允许设置引用数据类型
-
在类上定义泛型
-
定义
class Point<T>{}
-
使用
Point<String> p = new Point<> ()
-
-
泛型通配符
“?” 通常用于方法的参数
表示: 只允许从对象中获取数据,不允许修改数据
例如:
public static void get(Person<?> temp){
temp.getAge()
}
-
设置泛型的上限和下限
-
类和方法:设置泛型上限( ? extends 类)
public class Person<T extends Number> { private String name; private T age; public Person(String name, T age) { this.name = name; this.age = age; } public String getName(){ return this.name; } } // ------------------- public class Main { public static void main(String[] args) { Person<Double> p = new Person("张三",33); System.out.println(p.getName()); get(p); } public static void get(Person<? extends Number> person){ System.out.println(person.getName()); } }
-
方法: 设置泛型下限( ? super 类)
public static void get(Person<? super Double> person){ System.out.println(person.getName()); }
-
-
泛型接口
-
定义泛型接口,在子类继续声明泛型
public interface IMessage<T>{}
class MessageImpel<s> implements IMessage{}
public interface Person<T> { public abstract void show(); } // ------ public class YellowPerson<S> implements Person { private S name; public YellowPerson(S name) { this.name = name; } @Override public void show() { System.out.println("我是"+this.name); } }
-
定义泛型接口,在子类设置泛型
public interface IMessage<T>{}
class MessageImpel<s> implements IMessage<String>{}
-
-
定义泛型方法
public static <T> T[] fun(T…args){方法体}