-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathStringArrayUtils.java
More file actions
47 lines (38 loc) · 1.69 KB
/
StringArrayUtils.java
File metadata and controls
47 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.dtcc.exams.arrays;
import java.util.Arrays;
public class StringArrayUtils {
/**
* @param arrayToBeSpliced - array to be evaluated
* @param startingIndex - starting index of array to be spliced
* @param endingIndex - ending index of array
* @return an array with all elements between `startingIndex` and `endingIndex`
*/
public static String[] getSubArray(String[] arrayToBeSpliced, int startingIndex, int endingIndex) {
if(startingIndex < 0 && endingIndex < 0){
throw new IllegalArgumentException();
}else {
String[] subarray = new String[endingIndex- startingIndex + 1];
subarray = Arrays.asList(arrayToBeSpliced)
.subList(startingIndex, endingIndex)
.toArray(new String[0]);
return subarray;
//new String[]{Arrays.toString(subarray)};
}}
/**
* @param arrayToBeSpliced - array to be evaluated
* @param startingIndex - starting index of array to be spliced
* @return an array all elements between after `startingIndex`
*/
public static String[] getEndingArray(String[] arrayToBeSpliced, int startingIndex) {
if(startingIndex < 0 ) {
throw new IndexOutOfBoundsException();
}else if (startingIndex > arrayToBeSpliced.length){
throw new IllegalArgumentException();
}
else {
String[] subarray = new String[arrayToBeSpliced.length- startingIndex + 1];
subarray = Arrays.asList(arrayToBeSpliced)
.subList(startingIndex, arrayToBeSpliced.length)
.toArray(new String[0]);
return subarray;
}}}