Jack Mustacato 8 лет назад
Родитель
Сommit
f578ab64a1
1 измененных файлов: 9 добавлений и 9 удалений
  1. 9
    9
      exercises/atbash-cipher/.meta/src/reference/java/Atbash.java

+ 9
- 9
exercises/atbash-cipher/.meta/src/reference/java/Atbash.java Просмотреть файл

@@ -9,36 +9,36 @@ class Atbash {
9 9
 
10 10
     String encode(String input) {
11 11
         String encoded = stripInvalidCharacters(input).toLowerCase();
12
-        String cyphered = "";
12
+        StringBuilder cyphered = new StringBuilder(input.length());
13 13
 
14 14
         for (char c : encoded.toCharArray()) {
15
-            cyphered += applyCipher(c);
15
+            cyphered.append(applyCipher(c));
16 16
         }
17 17
 
18
-        return splitIntoFiveLetterWords(cyphered);
18
+        return splitIntoFiveLetterWords(cyphered.toString());
19 19
     }
20 20
 
21 21
     String decode(String input) {
22 22
         String encoded = stripInvalidCharacters(input).toLowerCase();
23
-        String deciphered = "";
23
+        StringBuilder deciphered = new StringBuilder(input.length());
24 24
 
25 25
         for (char c : encoded.toCharArray()) {
26
-            deciphered += applyCipher(c);
26
+            deciphered.append(applyCipher(c));
27 27
         }
28 28
 
29
-        return deciphered;
29
+        return deciphered.toString();
30 30
     }
31 31
 
32 32
     String stripInvalidCharacters(String input) {
33
-        String filteredValue = "";
33
+        StringBuilder filteredValue = new StringBuilder(input.length());
34 34
 
35 35
         for (char c : input.toCharArray()) {
36 36
             if (Character.isLetterOrDigit(c)) {
37
-                filteredValue += c;
37
+                filteredValue.append(c);
38 38
             }
39 39
         }
40 40
 
41
-        return filteredValue;
41
+        return filteredValue.toString();
42 42
     }
43 43
 
44 44
     private char applyCipher(char input) {