|
@@ -1,37 +1,31 @@
|
1
|
1
|
package com.zipcodewilmington.danny_do_better_exercises;
|
2
|
2
|
|
3
|
3
|
/**
|
4
|
|
- * Created by dan on 6/14/17.
|
|
4
|
+ * Refactored
|
5
|
5
|
*/
|
6
|
6
|
public class StringUtilities {
|
7
|
7
|
|
8
|
8
|
public static String getHelloWorld() {
|
9
|
|
-
|
10
|
9
|
return "Hello World";
|
11
|
10
|
}
|
12
|
11
|
|
13
|
12
|
public static String concatenation(String firstSegment, String secondSegment){
|
14
|
|
-
|
15
|
13
|
return firstSegment + secondSegment;
|
16
|
14
|
}
|
17
|
15
|
|
18
|
16
|
public static String concatenation(int firstSegment, String secondSegment){
|
19
|
|
-
|
20
|
17
|
return firstSegment + secondSegment;
|
21
|
18
|
}
|
22
|
19
|
|
23
|
20
|
public static String getPrefix(String input){
|
24
|
|
-
|
25
|
|
- return input.substring(0,3);
|
|
21
|
+ return input.substring(0,3); //returns a range of characters from the string from index positions 0 - 3 (prefix)
|
26
|
22
|
}
|
27
|
23
|
|
28
|
24
|
public static String getSuffix(String input){
|
29
|
|
-
|
30
|
25
|
return input.substring(2);
|
31
|
26
|
}
|
32
|
27
|
|
33
|
28
|
public static Boolean compareTwoStrings(String inputValue, String comparableValue){
|
34
|
|
-
|
35
|
29
|
return inputValue.equals(comparableValue) ;
|
36
|
30
|
}
|
37
|
31
|
|
|
@@ -41,8 +35,8 @@ public class StringUtilities {
|
41
|
35
|
if (middleIndex % 2 == 0){
|
42
|
36
|
middleIndex = middleIndex - 1;
|
43
|
37
|
}
|
44
|
|
- char middleCharacter = inputValue.charAt(middleIndex);
|
45
|
|
- return middleCharacter;
|
|
38
|
+
|
|
39
|
+ return inputValue.charAt(middleIndex);
|
46
|
40
|
}
|
47
|
41
|
|
48
|
42
|
public static String getFirstWord(String spaceDelimitedString) {
|
|
@@ -56,9 +50,6 @@ public class StringUtilities {
|
56
|
50
|
}
|
57
|
51
|
|
58
|
52
|
public static String reverseTheTwo(String stringToReverse){
|
59
|
|
-
|
60
|
|
- String reverse = new StringBuffer(stringToReverse).reverse().toString();
|
61
|
|
-
|
62
|
|
- return reverse;
|
|
53
|
+ return new StringBuffer(stringToReverse).reverse().toString();
|
63
|
54
|
}
|
64
|
|
-}
|
|
55
|
+}
|