Skip to content

Commit 402476e

Browse files
committed
added Stream comparingByValue by reverse order example
1 parent 07e8b58 commit 402476e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package java8.stream;
2+
3+
import java.util.Comparator;
4+
import java.util.LinkedHashMap;
5+
import java.util.Map;
6+
7+
public class StreamDemo11
8+
{
9+
public static void main(String[] args)
10+
{
11+
Map<Integer,String> map=new LinkedHashMap<Integer, String>();
12+
map.put(5, "five");
13+
map.put(1, "one");
14+
map.put(4, "four");
15+
map.put(3, "three");
16+
map.put(2, "two");
17+
18+
System.out.println(map); // {5=five, 1=one, 4=four, 3=three, 2=two}
19+
20+
map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).forEach(System.out::println);
21+
}
22+
}

0 commit comments

Comments
 (0)