The following code is available:
public Product() {} public Integer getCod() { return cod; } public void setCod(Integer cod) { this.cod = cod; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getNumber() { return number; } public void setNumber(Integer number) { this.number = number; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public Double getDiscount() { return discount; } public void setDiscount(Double discount) { this.discount = discount; } public Integer getBatchQuantity() { return batchQuantity; } public void setBatchQuantity(Integer batchQuantity) { this.batchQuantity = batchQuantity; } @Override public String toString() { return "Product{" + "cod=" + cod + ", name='" + name + '\'' + ", number=" + number + ", description='" + description + '\'' + ", price=" + price + ", discount=" + discount + ", batchQuantity=" + batchQuantity + '}'; } } And the following button code sorter:
/** * Кнопка сортировщик */ @FXML public void onSortAction() { loadData(); message.setText(""); // сортировка по возрастанию названия и цены if (nameAsc.isSelected() == true && priceAsc.isSelected() == true) { List sortedProductList = productList.stream().sorted((o1, o2) -> -o1.getName().compareTo(o2.getName())).collect(Collectors.toList()); sortedProductList = productList.stream().sorted((o1, o2) -> -o1.getPrice().compareTo(o2.getPrice())).collect(Collectors.toList()); productList = new ArrayList<Product>(); productList = sortedProductList; } } I was able to sort by one field, how can I make it possible to sort this list by both fields?