Java基础之Properties类、Collections集合工具类

Properties时Hashtable的子类,主要进行属性的操作,属性的最大特点是利用字符串设置key与value。

public class Properties extends Hashtable<Object,Object>
在使用Properties类时,不需要设置泛型
public Object setProperty(String key, String value)
public String getProperty(String key)//如果key不存在,返回null
public String getProperty(String key, String defaultValue)//如果key不存在,返回默认值
 1  Properties properties = new Properties();
 2         properties.setProperty("BJ","北京");
 3         properties.setProperty("SH","上海");
 4         properties.setProperty("SZ","深圳");
 5         try {
 6             //使用Properties类,将设置的信息写到指定磁盘文件中
 7             properties.store(new FileOutputStream(new File("E:"+File.separator+"area.properties")),"zhushi");
 8         } catch (IOException e) {
 9             e.printStackTrace();
10         }
11 
12         //通过文件流读取属性内容
13         try {
14             properties.load(new FileInputStream(new File("E:"+File.separator+"area.properties")));
15             System.out.println(properties.getProperty("BJ"));
16         } catch (IOException e) {
17             e.printStackTrace();
18         }
Collections集合工具类
@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c,
                                              T... elements)//添加数据到集合中
public static <T extends Comparable<? super T>> void sort(List<T> list)//对集合中欧冠元素排序
public static void reverse(List<?> list)//反转集合中的元素
解释:Collection与Collections的区别?
  》Collection是集合操作的接口
  》Collections是集合操作的工具类,可以进行List、Map、Set集合的操作

转载于:https://www.cnblogs.com/in-the-game-of-thrones/p/11336175.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值