Вы не упомянули, какая строка кода вызывает эту ошибку.Я не уверен, какой StringUtils вы использовали здесь, com.sun.deploy.util.StringUtils
не имеет .isEmpty()
метод.Поэтому я переопределил это.
Вот рабочий код вашей проблемы:
public static void main(String[] args){
getShipmentInpickingTime(new ArrayList<Shipments>(){{
add(new Shipments("12:00"));
add(new Shipments("12:03"));
add(new Shipments("12:02"));
}});
}
private static void getShipmentInpickingTime(List<Shipments> shipments) {
DateFormat sdf = new SimpleDateFormat("hh:mm");
System.out.println(shipments.toString());
Collections.sort(shipments, (o1, o2) -> {
try {
if ((!"null".equals(o1.getShipmentPickingTime())
&& !(o1.getShipmentPickingTime() == null || o1.getShipmentPickingTime().length() < 1))
&& (!"null".equals(o2.getShipmentPickingTime())
&& !(o2.getShipmentPickingTime() == null || o2.getShipmentPickingTime().length() < 1))) {
return sdf.parse(o1.getShipmentPickingTime()).compareTo(sdf.parse(o2.getShipmentPickingTime()));
}
} catch (ParseException e) {
e.printStackTrace();
}
return 0;
});
System.out.println(shipments.toString());
}
Содержание класса пересылок:
public class Shipments {
private String shipmentPickingTime;
public Shipments(String shipmentPickingTime) {
this.shipmentPickingTime = shipmentPickingTime;
}
public String getShipmentPickingTime() {
return shipmentPickingTime;
}
public void setShipmentPickingTime(String shipmentPickingTime) {
this.shipmentPickingTime = shipmentPickingTime;
}
@Override
public String toString() {
return "Shipments{" +
"shipmentPickingTime='" + shipmentPickingTime + '\'' +
'}';
}
}
Вывод:
[Shipments{shipmentPickingTime='12:00'}, Shipments{shipmentPickingTime='12:03'}, Shipments{shipmentPickingTime='12:02'}]
[Shipments{shipmentPickingTime='12:00'}, Shipments{shipmentPickingTime='12:02'}, Shipments{shipmentPickingTime='12:03'}]