|
|
@@ -1,4 +1,4 @@
|
|
1
|
|
-
|
|
|
1
|
+import java.util.Arrays;
|
|
2
|
2
|
/**
|
|
3
|
3
|
* Created by leon on 1/29/18.
|
|
4
|
4
|
*/
|
|
|
@@ -89,16 +89,12 @@ public class StringArrayUtils {
|
|
89
|
89
|
*/
|
|
90
|
90
|
boolean returnPal = false;
|
|
91
|
91
|
String [] reverseArray = reverse(array);
|
|
92
|
|
- /*
|
|
93
|
|
- *
|
|
94
|
|
- */
|
|
95
|
92
|
for(int i = 0; i < array.length; i++){
|
|
96
|
|
- System.out.println("array[i] " + array[i] + " reverseArray[i] " + reverseArray[i]);
|
|
|
93
|
+ // System.out.println("array[i] " + array[i] + " reverseArray[i] " + reverseArray[i]);
|
|
97
|
94
|
if(array[i].equals(reverseArray[i])){
|
|
98
|
95
|
returnPal = true;
|
|
99
|
96
|
}
|
|
100
|
97
|
}
|
|
101
|
|
-
|
|
102
|
98
|
return returnPal;
|
|
103
|
99
|
}
|
|
104
|
100
|
|
|
|
@@ -111,21 +107,28 @@ public class StringArrayUtils {
|
|
111
|
107
|
* if(isPangramic.length() < letters){
|
|
112
|
108
|
* }
|
|
113
|
109
|
*/
|
|
114
|
|
- int letters = 26;
|
|
115
|
|
- boolean pangram = false;
|
|
116
|
|
-
|
|
117
|
|
- if(array.length < letters){
|
|
118
|
|
- pangram = true;
|
|
119
|
|
- }
|
|
120
|
|
- if(array.length == letters){
|
|
121
|
|
- pangram = false;
|
|
122
|
|
- }else{
|
|
123
|
|
-
|
|
124
|
|
- pangram = true;
|
|
125
|
|
-
|
|
|
110
|
+ // int letters = 26;
|
|
|
111
|
+ // boolean pangram = false;
|
|
|
112
|
+ //
|
|
|
113
|
+ // if(array.length < letters){
|
|
|
114
|
+ // pangram = true;
|
|
|
115
|
+ // }
|
|
|
116
|
+ // if(array.length == letters){
|
|
|
117
|
+ // pangram = false;
|
|
|
118
|
+ // }else{
|
|
|
119
|
+ // pangram = true;
|
|
|
120
|
+ // }
|
|
|
121
|
+ // return pangram;
|
|
|
122
|
+ String stringToArray = array.toString();
|
|
|
123
|
+ String str = stringToArray.toLowerCase();
|
|
|
124
|
+ boolean answer = false;
|
|
|
125
|
+ for (char start = 'a';start <='z';++start){
|
|
|
126
|
+ if (!str.contains(String.valueOf(start))){
|
|
|
127
|
+ answer = true;
|
|
|
128
|
+ break;
|
|
|
129
|
+ }
|
|
126
|
130
|
}
|
|
127
|
|
-
|
|
128
|
|
- return pangram;
|
|
|
131
|
+ return answer;
|
|
129
|
132
|
}
|
|
130
|
133
|
|
|
131
|
134
|
/**
|
|
|
@@ -134,9 +137,7 @@ public class StringArrayUtils {
|
|
134
|
137
|
* @return number of occurrences the specified `value` has occurred
|
|
135
|
138
|
*/ // TODO
|
|
136
|
139
|
public static int getNumberOfOccurrences(String[] array, String value) {
|
|
137
|
|
- /*
|
|
138
|
|
- *
|
|
139
|
|
- */
|
|
|
140
|
+
|
|
140
|
141
|
int count = 0;
|
|
141
|
142
|
for(int i = 0;i < array.length;i++){
|
|
142
|
143
|
if(array[i] == value){
|
|
|
@@ -153,21 +154,19 @@ public class StringArrayUtils {
|
|
153
|
154
|
*/ // TODO
|
|
154
|
155
|
public static String[] removeValue(String[] array, String valueToRemove) {
|
|
155
|
156
|
StringBuilder sb = new StringBuilder();
|
|
156
|
|
-
|
|
|
157
|
+
|
|
157
|
158
|
//Looping through array
|
|
158
|
159
|
for(int index = 0;index < array.length;index++){
|
|
159
|
160
|
//if the array value does not equal
|
|
160
|
161
|
//the value to remove, then add the values to a temp array
|
|
161
|
|
-
|
|
|
162
|
+
|
|
162
|
163
|
if(array[index] != valueToRemove ){
|
|
163
|
|
- sb.append(array[index] + "~");
|
|
164
|
|
-
|
|
|
164
|
+ sb.append(array[index] + "~");
|
|
|
165
|
+
|
|
165
|
166
|
}
|
|
166
|
|
-
|
|
167
|
|
-
|
|
|
167
|
+
|
|
168
|
168
|
}
|
|
169
|
169
|
String answer = sb.toString();
|
|
170
|
|
-
|
|
171
|
170
|
String [] temp = answer.split("~");
|
|
172
|
171
|
return temp;
|
|
173
|
172
|
}
|
|
|
@@ -177,10 +176,34 @@ public class StringArrayUtils {
|
|
177
|
176
|
* @return array of Strings with consecutive duplicates removes
|
|
178
|
177
|
*/ // TODO
|
|
179
|
178
|
public static String[] removeConsecutiveDuplicates(String[] array) {
|
|
180
|
|
-
|
|
181
|
|
-
|
|
182
|
|
-
|
|
183
|
|
- return null;
|
|
|
179
|
+ //created emptry array with length of array
|
|
|
180
|
+ //created an
|
|
|
181
|
+ String [] answer = new String[array.length];
|
|
|
182
|
+ int i = 0;
|
|
|
183
|
+ answer[i]=array[0];
|
|
|
184
|
+ i++;
|
|
|
185
|
+ for(int j=1;j<array.length;j++){
|
|
|
186
|
+ if(!answer[i-1].equals(array[j])){
|
|
|
187
|
+ answer[i]=array[j];
|
|
|
188
|
+ i++;
|
|
|
189
|
+ }
|
|
|
190
|
+ }
|
|
|
191
|
+ String [] newArray = new String [i];
|
|
|
192
|
+ //copies a source array from a specific beginning position to the destination array
|
|
|
193
|
+ // from the mentioned position.
|
|
|
194
|
+ // No. of arguments to be copied are decided by len argument.
|
|
|
195
|
+ System.arraycopy(answer, 0, newArray, 0, i);
|
|
|
196
|
+ return newArray;
|
|
|
197
|
+ }
|
|
|
198
|
+
|
|
|
199
|
+ public static int counter(String[] array){
|
|
|
200
|
+ int counter = 0;
|
|
|
201
|
+ for(int index = 0; index < array.length-1; index++){
|
|
|
202
|
+ if(array[index].equals(array[index+1])){
|
|
|
203
|
+ counter = counter+=1;
|
|
|
204
|
+ }
|
|
|
205
|
+ }
|
|
|
206
|
+ return counter;
|
|
184
|
207
|
}
|
|
185
|
208
|
|
|
186
|
209
|
/**
|
|
|
@@ -188,7 +211,22 @@ public class StringArrayUtils {
|
|
188
|
211
|
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
|
|
189
|
212
|
*/ // TODO
|
|
190
|
213
|
public static String[] packConsecutiveDuplicates(String[] array) {
|
|
191
|
|
- return null;
|
|
|
214
|
+ StringBuilder pack = new StringBuilder(array[0]);
|
|
|
215
|
+ String [] answer = new String[array.length-counter(array)];
|
|
|
216
|
+ int index = 0;
|
|
|
217
|
+ for(int i=1;i<array.length;i++){
|
|
|
218
|
+ if(array[i-1].equals(array[i])){
|
|
|
219
|
+ pack.append(array[i]);
|
|
|
220
|
+
|
|
|
221
|
+ } else{
|
|
|
222
|
+ answer[index] = pack.toString();
|
|
|
223
|
+ pack.setLength(0);
|
|
|
224
|
+ pack.append(array[i]);
|
|
|
225
|
+ index++;
|
|
|
226
|
+ }
|
|
|
227
|
+ }
|
|
|
228
|
+ answer[index]=pack.toString();
|
|
|
229
|
+ return answer;
|
|
192
|
230
|
}
|
|
193
|
231
|
|
|
194
|
232
|
}
|