|
|
@@ -50,13 +50,13 @@ public class StringArrayUtils {
|
|
50
|
50
|
* @return true if the array contains the specified `value`
|
|
51
|
51
|
*/ // TODO
|
|
52
|
52
|
public static boolean contains(String[] array, String value) {
|
|
53
|
|
- String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
|
|
54
|
|
- if (Arrays.asList(arr).contains("quick") == true){
|
|
55
|
|
- return true;
|
|
|
53
|
+ String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
|
|
|
54
|
+ if (Arrays.asList(arr).contains("quick") == true){
|
|
|
55
|
+ return true;
|
|
56
|
56
|
}
|
|
57
|
57
|
else{
|
|
58
|
58
|
}
|
|
59
|
|
- return false ;
|
|
|
59
|
+ return false ;
|
|
60
|
60
|
}
|
|
61
|
61
|
|
|
62
|
62
|
/**
|
|
|
@@ -64,7 +64,14 @@ public class StringArrayUtils {
|
|
64
|
64
|
* @return an array with identical contents in reverse order
|
|
65
|
65
|
*/ // TODO
|
|
66
|
66
|
public static String[] reverse(String[] array) {
|
|
67
|
|
- return null;
|
|
|
67
|
+ for (int i=0; i<array.length/2;i++){
|
|
|
68
|
+ String temp = array[i];
|
|
|
69
|
+ array[i] = array[array.length-1-i];
|
|
|
70
|
+ array[array.length-1-i] = temp;
|
|
|
71
|
+
|
|
|
72
|
+ }
|
|
|
73
|
+
|
|
|
74
|
+ return array;
|
|
68
|
75
|
}
|
|
69
|
76
|
|
|
70
|
77
|
/**
|
|
|
@@ -72,7 +79,36 @@ public class StringArrayUtils {
|
|
72
|
79
|
* @return true if the order of the array is the same backwards and forwards
|
|
73
|
80
|
*/ // TODO
|
|
74
|
81
|
public static boolean isPalindromic(String[] array) {
|
|
|
82
|
+ String[] newArr = new String[array.length]; //newArr is a copy of original array
|
|
|
83
|
+ //newArray[i] = array[array.length-i-1];
|
|
|
84
|
+ for (int i=0;i<array.length;i++){
|
|
|
85
|
+ newArr[i]=array[array.length-i-1];
|
|
|
86
|
+
|
|
|
87
|
+ }
|
|
|
88
|
+ if (Arrays.equals(newArr,array)){
|
|
|
89
|
+ return true;
|
|
|
90
|
+
|
|
|
91
|
+ }
|
|
75
|
92
|
return false;
|
|
|
93
|
+
|
|
|
94
|
+ // if (array.length%2 ==0){
|
|
|
95
|
+ // for (int i=0; i<array.length/2;i++){
|
|
|
96
|
+ // String temp = array[i];
|
|
|
97
|
+ // array[i] = array[array.length-1];
|
|
|
98
|
+ // array[array.length-1] = temp;
|
|
|
99
|
+ // //reverse the original array
|
|
|
100
|
+ // }
|
|
|
101
|
+ // }
|
|
|
102
|
+ // if (Arrays.equals(newArr,array)){
|
|
|
103
|
+ // return true;
|
|
|
104
|
+ // }
|
|
|
105
|
+ // // else if(!array[0].equals(array[array.length-1])){
|
|
|
106
|
+ // // return false;
|
|
|
107
|
+ // // }
|
|
|
108
|
+ // else{
|
|
|
109
|
+ // return false;
|
|
|
110
|
+ // }
|
|
|
111
|
+
|
|
76
|
112
|
}
|
|
77
|
113
|
|
|
78
|
114
|
/**
|
|
|
@@ -80,6 +116,7 @@ public class StringArrayUtils {
|
|
80
|
116
|
* @return true if each letter in the alphabet has been used in the array
|
|
81
|
117
|
*/ // TODO
|
|
82
|
118
|
public static boolean isPangramic(String[] array) {
|
|
|
119
|
+
|
|
83
|
120
|
return false;
|
|
84
|
121
|
}
|
|
85
|
122
|
|
|
|
@@ -117,5 +154,4 @@ public class StringArrayUtils {
|
|
117
|
154
|
return null;
|
|
118
|
155
|
}
|
|
119
|
156
|
|
|
120
|
|
-
|
|
121
|
157
|
}
|