本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:如何将Map键值的下划线转为驼峰;
例,将HashMap实例extMap键值下划线转为驼峰:
代码:
HashMap<String,Object> extMap = new HashMap<>();
extMap.put("ORGAN_NAME","四个空格");
extMap.put("WEB_SITE","https://www.4spaces.org");
HashMap camelcaseExtMap = new HashMap();
for (Map.Entry<String, Object> entry : extMap.entrySet()) {
camelcaseExtMap.put(CaseUtils.toCamelCase(entry.getKey(), false, new char[]{'_'}), entry.getValue());
}
camelcaseExtMap.keySet().stream().forEach(System.out::println);