开发过程中我们最常用的map定义方式就是HashMap,如下:
Map<String, Float> labelKeyAndValeMap = new HashMap<>();
但是hashMap是无序的,但是现在开发过程中要求添加的顺序不被打乱,其实map是有方式的,
map的实现除了有HashMap还有TreeMap和LinkedHashMap
LinkedHashMap<String, String> labelMap = new LinkedHashMap<>();
List<String> columns = new ArrayList<>();
List<Map<String, String>> rowsMapList = new ArrayList<>();
columns.add("date");
String appType = emsAppCrashQueryForm.getAppType() == 1 ? "android" : "ios";
//表结构定义
List<EmsAppCrashEntity> androidList = appCrashDao.queryIdAndNameList(appType);
for (EmsAppCrashEntity crashEntity : androidList) {
String labelKey = (Tools.toFirstChar(crashEntity.getAppName()) + crashEntity.getAppType()).toUpperCase();
labelMap.put(labelKey, crashEntity.getAppName());
columns.add(labelKey);
}
上面的代码中labelMap就是使用LinkedHashMap实现,这个添加的顺序和columns数组添加顺序是一致的,按照添加的先后顺序