Mexi Liang 8 лет назад
Родитель
Сommit
a86f779cdf
1 измененных файлов: 21 добавлений и 7 удалений
  1. 21
    7
      StringArrayUtils.java

+ 21
- 7
StringArrayUtils.java Просмотреть файл

@@ -1,5 +1,5 @@
1
- 
2
-
1
+import java.util.List;
2
+import java.util.Arrays;
3 3
 /**
4 4
  * Created by leon on 1/29/18.
5 5
  */
@@ -9,7 +9,9 @@ public class StringArrayUtils {
9 9
      * @return first element of specified array
10 10
      */ // TODO
11 11
     public static String getFirstElement(String[] array) {
12
-        return null;
12
+        List<String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
13
+        String first = random.get(0);
14
+        return first;
13 15
     }
14 16
 
15 17
     /**
@@ -17,7 +19,9 @@ 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
+        List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
23
+        String second = random.get(1);
24
+        return second;
21 25
     }
22 26
 
23 27
     /**
@@ -25,7 +29,9 @@ public class StringArrayUtils {
25 29
      * @return last element in specified array
26 30
      */ // TODO
27 31
     public static String getLastElement(String[] array) {
28
-        return null;
32
+        List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
33
+        String last = random.get(array.length-1);
34
+        return last;
29 35
     }
30 36
 
31 37
     /**
@@ -33,7 +39,9 @@ public class StringArrayUtils {
33 39
      * @return second to last element in specified array
34 40
      */ // TODO
35 41
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
42
+        List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
43
+        String secondToLast = random.get(array.length-2);
44
+        return secondToLast;
37 45
     }
38 46
 
39 47
     /**
@@ -42,7 +50,13 @@ public class StringArrayUtils {
42 50
      * @return true if the array contains the specified `value`
43 51
      */ // TODO
44 52
     public static boolean contains(String[] array, String value) {
45
-        return false;
53
+       String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
54
+       if (Arrays.asList(arr).contains("quick") == true){
55
+        return true;
56
+        }
57
+        else{
58
+        }
59
+       return false ;
46 60
     }
47 61
 
48 62
     /**