Populating a HashMap with entries from a properties file

前端 未结 5 1207
南笙
南笙 2020-12-14 08:45

I want to populate a HashMap using the Properties class.
I want to load the entries in the .propeties file and then copy it into

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 09:26

    Java 8 Style:

    Properties properties = new Properties();
    // add  some properties  here
    Map map = new HashMap();
    
    map.putAll(properties.entrySet()
                         .stream()
                         .collect(Collectors.toMap(e -> e.getKey().toString(), 
                                                   e -> e.getValue().toString())));
    

提交回复
热议问题