类集(二)

来源:互联网 发布:mysql级联删除sql语句 编辑:程序博客网 时间:2024/04/27 20:17
Iterator
Iterator是一个接口,如果想要取得本接口实例化,只能够依靠Collection接口
在Collecion接口中:
publicIterator<E> iterator()
Iterateo中:
public boolean hasNext()
publicE next()
双向迭代:ListIterator
判断是否有前一个元素:boolean hasPrevious()
取得前一个元素:E next()
如果要想实现由前向后的输出,一定要先发生由后向前的输出
Enumeration
boolean hasMoreElements()
E nextElement()
Enumeration接口的实例化对象只能依靠Vector子类:
public Enumeration<E> elements()


properties:
是HashTable的子类,主要是进行属性懂的操作(属性的最大特点是利用字符串设置Key和value)
使用Properties类的时候,不需要设置泛型类型,只能够保存String;
public String getProperty(String key)//不存在,返回null
public Object setProperty(String key,String value)
public String getProperty(String key,String defaultValue)//不存在,返回默认值

properties提供了数据的输出操作
public void store(OutputStream out,String comments) throwsIOException
// 以适合使用 load(InputStream) 方法加载到 Properties 表中的格式,将此 Properties 表中的属性列表(键和元素对)写入输出流。
public void load(InputStream inStream)throwsIOException

对于属性文件和资源文件而言,除了可以使用Properties类读取以外,也可以使用ResourceBundle类
读取,这就是我们将属性文件设置成*.propertise的原因所在;

总结:
资源文件的特点:
key = value
资源文件中的数据一定都是字符串




0 0
原创粉丝点击