|
@@ -29,7 +29,7 @@ public class StringUtilities {
|
29
|
29
|
*/
|
30
|
30
|
public static String concatenation(int firstSegment, String secondSegment){
|
31
|
31
|
|
32
|
|
- return firstSegment + " " + secondSegment;
|
|
32
|
+ return firstSegment + secondSegment;
|
33
|
33
|
}
|
34
|
34
|
|
35
|
35
|
/**
|
|
@@ -38,7 +38,7 @@ public class StringUtilities {
|
38
|
38
|
*/
|
39
|
39
|
public static String getPrefix(String input){
|
40
|
40
|
|
41
|
|
- return input.substring(0,2);
|
|
41
|
+ return input.substring(0,3);
|
42
|
42
|
}
|
43
|
43
|
|
44
|
44
|
/**
|
|
@@ -56,6 +56,7 @@ public class StringUtilities {
|
56
|
56
|
* @return the equivalence of two strings, `inputValue` and `comparableValue`
|
57
|
57
|
*/
|
58
|
58
|
public static Boolean compareTwoStrings(String inputValue, String comparableValue){
|
|
59
|
+
|
59
|
60
|
return inputValue.equals(comparableValue);
|
60
|
61
|
}
|
61
|
62
|
|
|
@@ -65,7 +66,16 @@ public class StringUtilities {
|
65
|
66
|
*/
|
66
|
67
|
public static Character getMiddleCharacter(String inputValue){
|
67
|
68
|
|
68
|
|
- return 'A';
|
|
69
|
+ double mid = inputValue.length() / 2;
|
|
70
|
+ int full = (int)mid;
|
|
71
|
+
|
|
72
|
+ if (inputValue.length() % 2 != 0){
|
|
73
|
+ return inputValue.charAt(full);
|
|
74
|
+
|
|
75
|
+ } else {
|
|
76
|
+
|
|
77
|
+ return inputValue.charAt(full - 1);
|
|
78
|
+ }
|
69
|
79
|
}
|
70
|
80
|
|
71
|
81
|
/**
|
|
@@ -73,8 +83,10 @@ public class StringUtilities {
|
73
|
83
|
* @return the first sequence of characters
|
74
|
84
|
*/
|
75
|
85
|
public static String getFirstWord(String spaceDelimitedString){
|
|
86
|
+ String list[] = spaceDelimitedString.split(" ", 2);
|
|
87
|
+
|
|
88
|
+ return list[0];
|
76
|
89
|
|
77
|
|
- return spaceDelimitedString.split(" ")[0];
|
78
|
90
|
}
|
79
|
91
|
|
80
|
92
|
/**
|
|
@@ -83,7 +95,9 @@ public class StringUtilities {
|
83
|
95
|
*/
|
84
|
96
|
public static String getSecondWord(String spaceDelimitedString){
|
85
|
97
|
|
86
|
|
- return spaceDelimitedString.split(" ")[1];
|
|
98
|
+ String list[] = spaceDelimitedString.split(" ", 2);
|
|
99
|
+
|
|
100
|
+ return list[1];
|
87
|
101
|
}
|
88
|
102
|
|
89
|
103
|
/**
|
|
@@ -91,6 +105,13 @@ public class StringUtilities {
|
91
|
105
|
* @return an identical string with characters in reverse order.
|
92
|
106
|
*/
|
93
|
107
|
public static String reverseTheTwo(String stringToReverse){
|
94
|
|
- return null;
|
|
108
|
+
|
|
109
|
+ String flip = "";
|
|
110
|
+
|
|
111
|
+ for(int i = stringToReverse.length()-1; i >= 0; i--){
|
|
112
|
+ flip += stringToReverse.charAt(i);
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ return flip;
|
95
|
116
|
}
|
96
|
117
|
}
|