zoukankan      html  css  js  c++  java
  • Properties 转换成Map

    转自:http://feitianbenyue.iteye.com/blog/1759259

    对于Properties 转换成Map 的问题:

    第一时间想到的肯定有以下:
    1.  迭代出来  再 put 到 map 中去;
    2. commons 是否有工具类 ;
     
    可是 由于 Properties  实现了Map 接口,  所以有最最简单的 ,强制转换:
    package com.feilong.example.util;
    
    import java.util.Properties;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Set;
    
    public class PropertiesToMap {
        public static void main(String[] args) {
    
            Properties properties = new Properties();
    
    
            properties.setProperty("StrictHostKeyChecking", "no");
            properties.setProperty("app.version", "1.0");
    
            // Create a new HashMap and pass an instance of Properties. Properties
            // is an implementation of a Map which keys and values stored as in a string.
            Map<String, String> map = new HashMap<String, String>((Map) properties);
    
    
            // Get the entry set of the Map and print it out.
    
            Set propertySet = map.entrySet();
            for (Object o : propertySet) {
                Map.Entry entry = (Map.Entry) o;
                System.out.printf("%s = %s%n", entry.getKey(), entry.getValue());
            }
        }
    }

    对于**.properties文件中数据的读取感觉很好用。

  • 相关阅读:
    [BZOJ 2653]middle
    svn提交错误
    查看当前功能地址
    后台纯代码--短信验证
    图片验证码~~~之后台生成随机数
    小程序之~~登录后台代码
    小程序登录过程简介
    小程序之~微信登录后台代码
    小程序之~~基于微信登录,后台代码
    小程序之~~短信验证
  • 原文地址:https://www.cnblogs.com/tv151579/p/3269277.html
Copyright © 2011-2022 走看看