List<ShipInventoryReportDataVO> lstShipInvData = shipInventoryReportDAO
.getShippableInventoryReportData(inputVO, true);
ShipInventoryReportDataVO
is my object class and getting the data from a stored procedure. In ShipInventoryReportDataVO
object class I have a field called productCode
and the data of productCode will in alphanumeric like
0123,
654,
sparem,
3205,
the wholeland,
10,
1.
when I am sorting the productCode
which is in object class, I am getting the output as
0123
1
10
3205
654
sparem
wholeland.
this is the code I tried to sort
List<ShipInventoryReportDataVO> lstShipInvData = shipInventoryReportDAO.getShippableInventoryReportData(inputVO, true);
Collections.sort(lstShipInvData,
(o1, o2) ->
(o1.getProductCode().compareTo(o2.getProductCode()))
);
and this
lstShipInvData = (List) lstShipInvData.stream()
.sorted(Comparator.comparing(
ShipInventoryReportDataVO::getProductCode
))
.collect(Collectors.toList());
both the codes gets output as above
but I need the output as below
1
10
654
0123
3205
sparem
wholeland
This is the code which i tried now
List<ShipInventoryReportDataVO> productCodes = shipInventoryReportDAO.getShippableInventoryReportData(inputVO, true);
Comparator<String> byProductCode = Comparator.comparingInt(String::length)
.thenComparing(Comparator.naturalOrder());
productCodes.sort(Comparator.comparing(
ShipInventoryReportDataVO::getProductCode, byProductCode
));
productCodes.forEach(System.out::println);
System.out.println(productCodes.toString());