質問編集履歴
3
追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,17 +32,47 @@
|
|
32
32
|
|
33
33
|
```Java
|
34
34
|
|
35
|
-
|
35
|
+
package first;
|
36
36
|
|
37
|
-
71 | String[] textlist = time.split(".");
|
38
37
|
|
39
|
-
72!| String year = textlist[0];
|
40
38
|
|
41
|
-
|
39
|
+
import java.text.MessageFormat;
|
42
40
|
|
43
|
-
74 | String date = String.format("%2s", textlist[2]).replace(" ", "0");
|
44
41
|
|
42
|
+
|
43
|
+
public class Main {
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public static void main(String[] args) {
|
48
|
+
|
49
|
+
// TODO 自動生成されたメソッド・スタブ
|
50
|
+
|
51
|
+
// ================================================================================
|
52
|
+
|
53
|
+
// MAIN
|
54
|
+
|
55
|
+
// ================================================================================
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
String time = "2016.8.2";
|
60
|
+
|
61
|
+
String[] textlist = time.split(".");
|
62
|
+
|
63
|
+
String year = textlist[0];
|
64
|
+
|
65
|
+
String month = String.format("%2s", textlist[1]).replace(" ", "0");
|
66
|
+
|
67
|
+
String date = String.format("%2s", textlist[2]).replace(" ", "0");
|
68
|
+
|
45
|
-
|
69
|
+
String text = MessageFormat.format("{0}{1}{2}", year, month, date);
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
}
|
46
76
|
|
47
77
|
```
|
48
78
|
|
@@ -56,7 +86,7 @@
|
|
56
86
|
|
57
87
|
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
|
58
88
|
|
59
|
-
at java_lesson/first.Main.main(Main.java:
|
89
|
+
at java_lesson/first.Main.main(Main.java:15)
|
60
90
|
|
61
91
|
```
|
62
92
|
|
2
追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,14 @@
|
|
62
62
|
|
63
63
|
|
64
64
|
|
65
|
+
### 備考
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
- textlist配列に無い要素を取り出そうとしていると怒られているので、原因はtime.split(".")が正常に値を返してないと思います。
|
70
|
+
|
71
|
+
|
72
|
+
|
65
73
|
### 環境
|
66
74
|
|
67
75
|
|
1
追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,14 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
### やりたいこと
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
- 文字列「2016.8.2」を「20160802」と整形したい。
|
26
|
+
|
27
|
+
|
28
|
+
|
21
29
|
### エラーが起きているコード
|
22
30
|
|
23
31
|
|
@@ -33,6 +41,8 @@
|
|
33
41
|
73 | String month = String.format("%2s", textlist[1]).replace(" ", "0");
|
34
42
|
|
35
43
|
74 | String date = String.format("%2s", textlist[2]).replace(" ", "0");
|
44
|
+
|
45
|
+
75 | String text = MessageFormat.format("{0}{1}{2}", year, month, date);
|
36
46
|
|
37
47
|
```
|
38
48
|
|