-1

私は次のオブジェクトを持っています:

 List<CartItem> cartItemsList = cart.getItems().stream()
                .sorted(Comparator.comparingDouble(f -> f.getProduct().getPrice()))
                .collect(Collectors.toList());

 Map<Product, Map<Customization, List<CartItem>>> map =cartItemsList.stream()
                .collect(Collectors.groupingBy(CartItem::getProduct,
                        Collectors.groupingBy(CartItem::getCustomizations)));

私の問題はマップに関するものです。最初の list(cartItemsList) で定義された順序を保持する必要があるため、マップは適切な解決策ではありません。順序を維持するためにlinkedHashMap(またはその他のソリューション)を使用する必要がありますか?どうすればよいですか?

4

1 に答える 1