|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.zipcodewilmington;
|
2
|
2
|
|
|
3
|
+
|
3
|
4
|
/**
|
4
|
5
|
* Created by leon on 1/29/18.
|
5
|
6
|
*/
|
|
@@ -9,7 +10,8 @@ public class StringArrayUtils {
|
9
|
10
|
* @return first element of specified array
|
10
|
11
|
*/ // TODO
|
11
|
12
|
public static String getFirstElement(String[] array) {
|
12
|
|
- return null;
|
|
13
|
+
|
|
14
|
+ return array[0];
|
13
|
15
|
}
|
14
|
16
|
|
15
|
17
|
/**
|
|
@@ -17,7 +19,8 @@ public class StringArrayUtils {
|
17
|
19
|
* @return second element in specified array
|
18
|
20
|
*/
|
19
|
21
|
public static String getSecondElement(String[] array) {
|
20
|
|
- return null;
|
|
22
|
+
|
|
23
|
+ return array[1];
|
21
|
24
|
}
|
22
|
25
|
|
23
|
26
|
/**
|
|
@@ -25,7 +28,8 @@ public class StringArrayUtils {
|
25
|
28
|
* @return last element in specified array
|
26
|
29
|
*/ // TODO
|
27
|
30
|
public static String getLastElement(String[] array) {
|
28
|
|
- return null;
|
|
31
|
+
|
|
32
|
+ return array[array.length - 1];
|
29
|
33
|
}
|
30
|
34
|
|
31
|
35
|
/**
|
|
@@ -33,7 +37,8 @@ public class StringArrayUtils {
|
33
|
37
|
* @return second to last element in specified array
|
34
|
38
|
*/ // TODO
|
35
|
39
|
public static String getSecondToLastElement(String[] array) {
|
36
|
|
- return null;
|
|
40
|
+
|
|
41
|
+ return array[array.length - 2];
|
37
|
42
|
}
|
38
|
43
|
|
39
|
44
|
/**
|
|
@@ -42,6 +47,12 @@ public class StringArrayUtils {
|
42
|
47
|
* @return true if the array contains the specified `value`
|
43
|
48
|
*/ // TODO
|
44
|
49
|
public static boolean contains(String[] array, String value) {
|
|
50
|
+ for(String counter : array) {
|
|
51
|
+ if(counter.equals(value)) {
|
|
52
|
+ return true;
|
|
53
|
+ }
|
|
54
|
+ }
|
|
55
|
+
|
45
|
56
|
return false;
|
46
|
57
|
}
|
47
|
58
|
|
|
@@ -50,7 +61,14 @@ public class StringArrayUtils {
|
50
|
61
|
* @return an array with identical contents in reverse order
|
51
|
62
|
*/ // TODO
|
52
|
63
|
public static String[] reverse(String[] array) {
|
53
|
|
- return null;
|
|
64
|
+ String[] reverseArray = new String[array.length];
|
|
65
|
+ for(int i = 0; i < array.length - 1; i++){
|
|
66
|
+ reverseArray[] += array[i];
|
|
67
|
+
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ return reverseArray;
|
54
|
72
|
}
|
55
|
73
|
|
56
|
74
|
/**
|