Date类:
概述:
Date类表示特定的瞬间,精确到毫秒;
构造方法:
1.public Date():分配Date对象并初始化此对象,以分配它的时间;
2.public Date(long Date):分配Date对象并初始化此对象,以表示自从标准基准时间以来的毫秒偏移;
成员方法:
1.public long getTime():获取时间,以毫秒为单位;
2.public void setTime(long time):设置时间;
DateFormat类:
概述:
DateFormat是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析时间或日期;
是抽象类,所以使用其子类SimpleDateFormat;
SimpleDateFormat构造方法:
1.public SimpleDateFormat():用默认的模式和默认语言环境的日期格式符号构造SimpleDateFormat;
2.public SimpleDateFormat(String pattern):用给定的模式和默认语言环境的日期格式符号构造SimpleDateFormat;
SimpleDateFormat成员方法:
1.public final String format(Date date):将Date类型的数据格式化为String类型;
2.public final Date parse(String source):将String类型的数据解析为Date类型;
模式字母:
y:年;
M:年中的月份;
d:月份中的天数;
H:一天中的小时数;
m:小时中的分钟数;
s:分钟中的毫秒数;
注意:再把一个字符串解析为Date类型的数据时,请注意模式,必须和给定的字符串相匹配;
Calendar类:
概述:
Calendar类是一个抽象类,它为特定瞬间与值诸如YEAR,MONTH,DAY_OF_MONTH,HOUR等日历字段之间的转换提供了一些方法,并用于操作日历字段;
日历类中的每个日历字段都是静态的成员变量,并且是int类型(例 public static YEAR);
成员方法:
1.public static Calendar getInstance():返回一个Calendar对象;
2.public int get(int field):返回给定的日历字段的值;
3.public void add(int field,int amount):根据日历的规则,为给定的日历字段添加或减去指定的时间量;
4.public final void set(int year,int month,int date):设置年月日,需要注意的是,月份是从0开始的,比如设置三月,month的值应为2;
集合:
数组和集合的区别:
数组虽然也可以存储对象,但长度是固定的,集合长度是可变的,数组中可以存储基本数据类型,集合只能存储对象;
集合分类:
Collection:
添加功能:
1.public boolean add(E e):追加一个元素;
2.public boolean addAll(Collection<? extends E>):将Collection中的所有元素添加到集合中;
删除功能:
1.public void clear():删除集合中的所有元素;
2,public boolean remove(Object o):移除集合中的指定元素;
3.public boolean removeAll(Collection<?> e):删除集合中Collection所包含的所有元素;
判断功能:
1.public boolean contains(Object o):判断集合中是否包含指定元素;
2.public boolean containsAll(Collection<?> e):判断集合是否包含Collection中的所有元素;
3.public boolean isEmpty():判断集合是否为空集合;
获取功能:
1.public Iterator <E> iterator:
返回在此Collection的元素上进行迭代的迭代器;
获取长度:
public int size():获取集合的长度;
交集功能:
public boolean retainAll(Collection c):保留集合中与Collection集合有交集的部分,并判断集合是否改变,如果元素改变,返回true,元素不变,返回false;
Iterator迭代器:
成员方法:
1.public boolean hasnext():判断是否有下一个元素可以迭代;
2.public E next():返回迭代器的下一个元素;
List的特有功能:
添加功能:
1.public void add(int index, E element):在指定位置添加元素;
2.public boolean addAll(int index,Collection<? extends E> e):在指定位置添加Collection中的所有元素;
获取功能:
1.public E get(int index):返回列表中指定位置的元素;
2.public ListIterator<E> listIterator():返回此列表元素的列表迭代器;
3.public ListIterator<E> listIterator(int index):返回从指定下标开始的列表迭代器;
删除功能:
1.public E remove(int index):移除指定位置的元素;
截取功能:
public List<E> subList(int fromindex,int offindex):截取,不解释;
ListIterator特有方法:
成员方法:
1.public boolean hasPrevious():判断是否有上一个元素;
2.public E previous:返回上一个元素;
3.public void add(E e):将指定的元素追加到列表;
注意:先正向遍历,才能逆向遍历,一般无意义,不实用;
List的子类特点:
ArrayList:
底层数据结构为数组,查询快,增删慢,因为线程不安全,效率高;
Vector:
底层数据结构为数组,查询快,增删慢,因为线程安全,效率低;
LinkedList:
底层数据结构为链表,查询慢,增删快,因为线程不安全,效率高;
Vector类特有功能(已过时):
1.public void addElement(E obj)[add]:添加;
2.public Eelement elementAt(int index)[get]:获取;
3.public Enumeration elements()[iterator]:类似迭代器;(public boolean hasMoreElement();public Object nextElement());
LinkedList类特有功能:
1.public void addFirst(E e)及addLast(E e):在指定位置添加元素;
2.public E getFirst()及getLast():获取指定位置元素;
3.public E removeFirst()及removeLast():移除指定位置元素;