My code is pretty long but I will include the relevant snippet. I am creating a GUI with elements of a store. I have a textfield called popularItemsTxt that contains the 3 most popular items of my list.
for(int i =0; i<3;i++) {
if(electronicStore.stock[i] != null) {
popularTxt.getItems().add(electronicStore.stock[i].toString());
}
}
However I have a button that computes the items in the final cart and when this button is pressed I want to be able to find the 3 most common items that have been added to that list. Any help/direction would be greatly appreciated.
btnComplete.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
//if the list has a minimum of 1 item
if (currentCartTxt.getItems().size() > 0) {
for(int i =0; i<3;i++) {
if(electronicStore.stock[i] != null) {
popularTxt.getItems().add(electronicStore.stock[i].toString());
List<ElectronicStore> topThree = Arrays.stream(electronicStore.stock)
.sorted(Comparator.comparing(ElectronicStore::createStore).reversed())
.limit(3)
.collect(Collectors.toList());
}
}
}
});
Right now the output is simply the first three items in my arraylist. I get an error when comparing