回答編集履歴
2
追記
answer
CHANGED
@@ -26,4 +26,60 @@
|
|
26
26
|
int i = 0;
|
27
27
|
for (String s : tm.values()) foo.set(i++, s);
|
28
28
|
System.out.println(foo);
|
29
|
+
```
|
30
|
+
**追記**
|
31
|
+
TreeMap がダメだったので、数字の切り出しと数値への変換を最初に行ったものの
|
32
|
+
ArrayList をソートしてみました。
|
33
|
+
2つの数値の差は int の範囲に収まる程度に小さいものとします。
|
34
|
+
数値が同じ場合は、文字列の降順になるようにしました。
|
35
|
+
```Java
|
36
|
+
import java.util.Collections;
|
37
|
+
import java.util.ArrayList;
|
38
|
+
|
39
|
+
public class Main {
|
40
|
+
public static void main(String[] args){
|
41
|
+
|
42
|
+
ArrayList<String> foo = new ArrayList<>();
|
43
|
+
foo.add("12:/search/?c=Games+Computers");
|
44
|
+
foo.add("5:/search/?c=Games+Computers");
|
45
|
+
foo.add("1:/search/?c=Games+Computers");
|
46
|
+
foo.add("13:/search/?c=Games+Computers");
|
47
|
+
foo.add("130:/search/?c=Games+Computers");
|
48
|
+
foo.add("7:/abc/?c=Games+Computers");
|
49
|
+
foo.add("7:/xyz/?c=Games+Computers");
|
50
|
+
|
51
|
+
ArrayList<E> bar = new ArrayList<>();
|
52
|
+
for (String s : foo) bar.add(new E(s));
|
53
|
+
|
54
|
+
Collections.sort(bar);
|
55
|
+
|
56
|
+
for (E e : bar) System.out.println("(\"" + e.o + "\");");
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
class E implements Comparable<E> {
|
61
|
+
int n;
|
62
|
+
String o, s[];
|
63
|
+
|
64
|
+
E(String str) {
|
65
|
+
o = str;
|
66
|
+
s = o.split(":");
|
67
|
+
n = Integer.parseInt(s[0]);
|
68
|
+
}
|
69
|
+
|
70
|
+
public int compareTo(E e) {
|
71
|
+
int d = e.n - n;
|
72
|
+
return d == 0 ? e.s[1].compareTo(s[1]) : d;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
実行結果
|
77
|
+
```text
|
78
|
+
("130:/search/?c=Games+Computers");
|
79
|
+
("13:/search/?c=Games+Computers");
|
80
|
+
("12:/search/?c=Games+Computers");
|
81
|
+
("7:/xyz/?c=Games+Computers");
|
82
|
+
("7:/abc/?c=Games+Computers");
|
83
|
+
("5:/search/?c=Games+Computers");
|
84
|
+
("1:/search/?c=Games+Computers");
|
29
85
|
```
|
1
誤字の修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Comparator を使うと、比較のたびに数字の切り出しと数値への変換が起こるので
|
2
2
|
データ数が多い場合遅くなるかもしれません。
|
3
3
|
|
4
4
|
そこで、TreeMap を使う方法もあります。
|