-1
我有兩個像下面那樣的ArrayList:以與具有一些共同屬性的對象的另一個對象列表相同的順序排列對象列表
List<HashMap<String, String>> mapList;
List<myclass> sortedDtos;
顧名思義,sortedDtos
已經排序。
`myclass` has a field called `jobNo`
The HashMap has a key called `jobNo`
基本上我想通過比較屬性jobNo
下令對sortedDtos
基於mapList
。
我如何在Java 8中執行此操作?
這似乎工作正常,也可能會提高效率。
List<String> jobNos = new ArrayList();
sortedDtos.stream().forEach(dto -> jobNos.add(dto.getJobNo()));
// sort maplist based on the sorting of the dtos
mapList.sort(Comparator.comparing(el -> jobNos.indexOf(el.get("jobNo"))));
請提供一些示例輸入和預期輸出。很難理解你要在這裏做什麼。 –
*這似乎工作正常,也可能會提高效率* ... https://codereview.stackexchange.com/? – nullpointer
我投票結束這個問題作爲題外話,因爲這個問題屬於另一個網站在堆棧交換網絡 - https://codereview.stackexchange.com/ – nullpointer