是否可以对List带有对象的接口进行排序ArrayList()?
List</*classname*/> list = new ArrayList<>();
我正在使用application.propertiesSpring boot 设置 List 界面中的值
ModuleNames.java
public class ModuleNames {
private String moduleId;
private String moduleName;
//getters & setters.
}
控制器
@RequestMapping(value = "/getModuleNames", method = { RequestMethod.GET })
public @ResponseBody List<String> getModuleNames() {
List<ModuleNames> moduleNamesList = new ArrayList<>();
moduleNamesList.add(new ModuleNames("Country", env.getProperty("bulkUpload.location.country")));
moduleNamesList.add(new ModuleNames("State", env.getProperty("bulkUpload.location.state")));
moduleNamesList.add(new ModuleNames("City", env.getProperty("bulkUpload.location.city")));
moduleNamesList.add(new ModuleNames("Area Pincode", env.getProperty("bulkUpload.location.areaPincode")));
return moduleNamesList;
有谁知道如何对列表进行排序。
我试过了
moduleNamesList.sort(Comparator.naturalOrder());
Collections.sort(moduleNamesList);
但两者似乎都不起作用。请在这里帮助我
PIPIONE
绝地无双
斯蒂芬大帝
相关分类