我有两个ArrayLists,如下所示,
private List<Patienthealthdata> patientHealthDataList = new ArrayList<Patienthealthdata>();
public List<Patienthealthdata> getPatientHealthDataList() {patientHealthDataSet = medicalHistoryService.getLatestMedicalHistoryDataAttributes(patient);Map<Integer, String> heightMap = new LinkedHashMap<Integer, String>();
List<Patienthealthdata> PatienthealthdataDummy = new ArrayList<Patienthealthdata>();
PatienthealthdataDummy.addAll(patientHealthDataSet);
for (int i = 0; i < PatienthealthdataDummy.size(); i++) {
if (PatienthealthdataDummy.get(i).getHealthdata().getName().contains("Height (ft)")) {
heightMap.put(1, PatienthealthdataDummy.get(i).getHealthDataValue());if (PatienthealthdataDummy.get(i).getHealthdata().getName().contains("Height (in)")) {
heightMap.put(2, PatienthealthdataDummy.get(i).getHealthDataValue());}for (Patienthealthdata patientHealthData : patientHealthDataSet) {
String valHeightInch = "";
String valHeightFt = "";
String newValue = "";
String groupName = patientHealthData.getHealthdata().getHealthdatagrouplinks().iterator().next().getHealthdatagroup().getName().trim();
if (groupName.equals(Constants.HELTH_GROUP_BMI)) {
if (patientHealthData.getHealthdata().getName().contains("Height (ft)")) { for (Entry<Integer, String> entry : heightMap.entrySet()) {if (entry.getKey() == 1) {
valHeightFt = entry.getValue();}
if (entry.getKey() == 2) {
valHeightInch = entry.getValue();
}}patientHealthDataList.add(patientHealthData);
} //End of If condition
我想在检索时按照预期的顺序对它们进行排序。任何帮助表示赞赏
答案 0 :(得分:0)
从你的标题中
使用迭代器
Iterator<E> iterator()
检索插入顺序中的元素
正如@Keyser先说的是arraylist在哪里?
<强>更新强>
要对地图进行排序,请使用此
for (Map.Entry<String, String> entry : heightMap.entrySet())
LinkedHashMap
按照插入顺序保存按键,而TreeMap
则通过比较器或元素的自然可比较顺序进行排序。