|
@@ -1,5 +1,4 @@
|
1
|
1
|
|
2
|
|
-
|
3
|
2
|
/**
|
4
|
3
|
* Created by dan on 6/14/17.
|
5
|
4
|
*/
|
|
@@ -8,7 +7,7 @@ public class StringUtilities {
|
8
|
7
|
* @return `Hello World` as a string
|
9
|
8
|
*/
|
10
|
9
|
public String getHelloWorld() {
|
11
|
|
- return null;
|
|
10
|
+ return "Hello World";
|
12
|
11
|
}
|
13
|
12
|
|
14
|
13
|
/**
|
|
@@ -17,7 +16,7 @@ public class StringUtilities {
|
17
|
16
|
* @return the concatenation of two strings, `firstSegment`, and `secondSegment`
|
18
|
17
|
*/
|
19
|
18
|
public String concatenation(String firstSegment, String secondSegment){
|
20
|
|
- return null;
|
|
19
|
+ return String.join("",firstSegment,secondSegment);
|
21
|
20
|
}
|
22
|
21
|
|
23
|
22
|
/**
|
|
@@ -26,7 +25,8 @@ public class StringUtilities {
|
26
|
25
|
* @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
|
27
|
26
|
*/
|
28
|
27
|
public String concatenation(int firstSegment, String secondSegment){
|
29
|
|
- return null;
|
|
28
|
+ Integer.toString(firstSegment);
|
|
29
|
+ return firstSegment + secondSegment;
|
30
|
30
|
}
|
31
|
31
|
|
32
|
32
|
/**
|
|
@@ -34,7 +34,7 @@ public class StringUtilities {
|
34
|
34
|
* @return the first 3 characters of `input`
|
35
|
35
|
*/
|
36
|
36
|
public String getPrefix(String input){
|
37
|
|
- return null;
|
|
37
|
+ return input.substring(0,3);
|
38
|
38
|
}
|
39
|
39
|
|
40
|
40
|
/**
|
|
@@ -42,7 +42,7 @@ public class StringUtilities {
|
42
|
42
|
* @return the last 3 characters of `input`
|
43
|
43
|
*/
|
44
|
44
|
public String getSuffix(String input){
|
45
|
|
- return null;
|
|
45
|
+ return input.substring(input.length()-3);
|
46
|
46
|
}
|
47
|
47
|
|
48
|
48
|
/**
|
|
@@ -51,7 +51,11 @@ public class StringUtilities {
|
51
|
51
|
* @return the equivalence of two strings, `inputValue` and `comparableValue`
|
52
|
52
|
*/
|
53
|
53
|
public Boolean compareTwoStrings(String inputValue, String comparableValue){
|
54
|
|
- return null;
|
|
54
|
+ if (inputValue.equals(comparableValue)) {
|
|
55
|
+ return true;
|
|
56
|
+ } else {
|
|
57
|
+ return false;
|
|
58
|
+ }
|
55
|
59
|
}
|
56
|
60
|
|
57
|
61
|
/**
|
|
@@ -59,15 +63,16 @@ public class StringUtilities {
|
59
|
63
|
* @return the middle character of `inputValue`
|
60
|
64
|
*/
|
61
|
65
|
public Character getMiddleCharacter(String inputValue){
|
62
|
|
- return null;
|
63
|
|
- }
|
64
|
66
|
|
|
67
|
+ return inputValue.charAt(((inputValue.length()-1)/2));
|
|
68
|
+
|
|
69
|
+ }
|
65
|
70
|
/**
|
66
|
71
|
* @param spaceDelimitedString a string, representative of a sentence, containing spaces
|
67
|
72
|
* @return the first sequence of characters
|
68
|
73
|
*/
|
69
|
74
|
public String getFirstWord(String spaceDelimitedString){
|
70
|
|
- return null;
|
|
75
|
+ return spaceDelimitedString.split(" ")[0];
|
71
|
76
|
}
|
72
|
77
|
|
73
|
78
|
/**
|
|
@@ -75,7 +80,7 @@ public class StringUtilities {
|
75
|
80
|
* @return the second word of a string delimited by spaces.
|
76
|
81
|
*/
|
77
|
82
|
public String getSecondWord(String spaceDelimitedString){
|
78
|
|
- return null;
|
|
83
|
+ return spaceDelimitedString.split(" ")[1];
|
79
|
84
|
}
|
80
|
85
|
|
81
|
86
|
/**
|
|
@@ -91,7 +96,7 @@ public class StringUtilities {
|
91
|
96
|
* @return an identical string with spaces removed.
|
92
|
97
|
*/
|
93
|
98
|
public String removeWhitespace(String input){
|
94
|
|
- return null;
|
|
99
|
+ return input.replaceAll(" ","");
|
95
|
100
|
}
|
96
|
101
|
|
97
|
102
|
/**
|
|
@@ -99,6 +104,6 @@ public class StringUtilities {
|
99
|
104
|
* @return an identical string with spaces in the front and end removed.
|
100
|
105
|
*/
|
101
|
106
|
public String trim(String input){
|
102
|
|
- return null;
|
|
107
|
+ return input.trim();
|
103
|
108
|
}
|
104
|
109
|
}
|