|
@@ -1,22 +1,29 @@
|
1
|
1
|
package rocks.zipcode.quiz5.arrays;
|
2
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.Arrays;
|
|
5
|
+import java.util.List;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* @author leon on 01/01/2019.
|
5
|
9
|
*/
|
6
|
10
|
public class ArrayUtils {
|
7
|
11
|
public static String getMiddleElement(String[] values) {
|
8
|
|
- return null;
|
|
12
|
+ return values[values.length / 2];
|
9
|
13
|
}
|
10
|
14
|
|
11
|
15
|
public static String[] removeMiddleElement(String[] values) {
|
12
|
|
- return null;
|
|
16
|
+ List<String> list = new ArrayList<>(Arrays.asList(values));
|
|
17
|
+ list.remove(getMiddleElement(values));
|
|
18
|
+
|
|
19
|
+ return list.toArray(new String[0]);
|
13
|
20
|
}
|
14
|
21
|
|
15
|
22
|
public static String getLastElement(String[] values) {
|
16
|
|
- return null;
|
|
23
|
+ return values[values.length - 1];
|
17
|
24
|
}
|
18
|
25
|
|
19
|
26
|
public static String[] removeLastElement(String[] values) {
|
20
|
|
- return null;
|
|
27
|
+ return Arrays.copyOfRange(values, 0, values.length - 1);
|
21
|
28
|
}
|
22
|
29
|
}
|