Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 060eeaa

Browse files
Merge pull request giantray#109 from Okeyja/patch-1
Update how-to-sort-a-mapkey-value-on-the-values-in-java.md
2 parents d6425e8 + 84c0667 commit 060eeaa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎contents/how-to-sort-a-mapkey-value-on-the-values-in-java.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
##`Map<Key,Value>`基于Value值排序
1+
##`Map<Key,Value>`基于Value值排序
22

3-
###方法1:
3+
###方法1:
44
使用TreeMap,可以参考下面的代码
55
```java
66
public class Testing {
@@ -43,7 +43,7 @@ class ValueComparator implements Comparator<String> {
4343
```
4444
译注:如果不自己写Comparator,treemap默认是用key来排序
4545

46-
###方法2:
46+
###方法2:
4747

4848
先通过linkedlist排好序,再放到LinkedHashMap中
4949
```java
@@ -74,4 +74,4 @@ public class MapUtil
7474
译注:这两种方法,我简单测试了下,如果map的size在十万级别以上,两者的耗时都是几百毫秒,第二个方法会快一些。否则,第一个方法快一些。因此,如果你处理的map,都是几十万级别以下的大小,两种方式随意使用,看个人喜欢了。
7575

7676
stackoverflow链接:
77-
http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java
77+
http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /