1、Properties是线程安全的,因为继承Hashtable
2、Properties存储元素的时候也是采用key和value的形式存储
3、Properties的key和value只支持String类型,不支持其它类型
4、Properties被称为属性类
示例代码:
public class PropertiesTest {
public static void main(String[] args) {
//创建Properties集合
Properties pro = new Properties();
//向集合中添加元素
pro.setProperty("url","jdbc:mysql://localhost:3306/newstudy");
pro.setProperty("driver","com.mysql.jdbc.Driver");
pro.setProperty("username","root");
pro.setProperty("password","123");
//通过key获取Value
String url = pro.getProperty("url");
String driver = pro.getProperty("driver");
String username = pro.getProperty("username", "root");
String password = pro.getProperty("password");
System.out.println(url);
System.out.println(driver);
System.out.println(username);
System.out.println(password);
}
}