砂の :
私は降順で結果を送信していますが、私は昇順で出力を得ます
List<myEntity> myData = new ArrayList<>();
Map<Integer,List<myEntity>> myid = new LinkedHashMap<>();
try {
myData = myService.getData(id);
myid = myData.stream().collect(Collectors.groupingBy(myEntity::getDataId));
ここMYDATAはDESC順にソートが、グループのデータIDでコレクションを作成した後、私のリストの取得には、昇順にソートされます。私は私のコレクションのリストが昇順ではない降順になりたいです。
MohammadReza Alagheband:
@Holgerはで説明したようにJavaの8グループ化しながら順序を維持していない、Collectors.groupingBy()は保証順序ないHashMapを返します。
ここで何ができるかです。
myid = myData.stream()
.collect(Collectors.groupingBy(MyEntity::getDataId,LinkedHashMap::new, toList()));
返しますLinkedHashMap<Integer, List<MyEntity>>
。コレクタによって使用されるリストのArrayListのように順序も維持されます。