以下是JsonNode
需要按“大小”键按字母顺序排序的内容。
List<JsonNode> listOfSizes =[{"size":"CAL KING","SKU_ID":"68454463"},
{"size":"KING","SKU_ID":"68454456"},
{"size":"TWIN XL","SKU_ID":"68454425"},
{"size":"QUEEN","SKU_ID":"68454449"},
{"size":"FULL","SKU_ID":"68454432"},
{"size":"TWIN","SKU_ID":"68454418"}]
排序的预期结果是:-
[{"size":"CAL KING","SKU_ID":"68454463"},
{"size":"FULL","SKU_ID":"68454432"},
{"size":"KING","SKU_ID":"68454456"},
{"size":"QUEEN","SKU_ID":"68454449"},
{"size":"TWIN","SKU_ID":"68454418"},
{"size":"TWIN XL","SKU_ID":"68454425"}]
我尝试按照以下方式进行操作:-
listOfSizes.stream().filter(sku -> NotEmpty(sku.get("size"))).sorted();
它不工作。我还尝试了更多方法,但没有得到预期的结果。
我现在正在学习 lambda 8。伙计们,如果您知道确切的逻辑,请指导我,因为我不想这样做foreach
。