|
|
@@ -188,13 +188,13 @@ public class StringArrayUtils {
|
|
188
|
188
|
if(!(excluded[newArrIndex-1]).equals(array[i])){
|
|
189
|
189
|
excluded[newArrIndex] = array[i];
|
|
190
|
190
|
newArrIndex++;
|
|
191
|
|
-
|
|
|
191
|
+
|
|
192
|
192
|
}
|
|
193
|
193
|
}
|
|
194
|
|
-
|
|
|
194
|
+
|
|
195
|
195
|
String[] newArr = new String[newArrIndex];
|
|
196
|
196
|
System.arraycopy(excluded, 0, newArr, 0, newArrIndex);
|
|
197
|
|
-
|
|
|
197
|
+
|
|
198
|
198
|
return newArr;
|
|
199
|
199
|
|
|
200
|
200
|
}
|
|
|
@@ -205,10 +205,38 @@ public class StringArrayUtils {
|
|
205
|
205
|
* occurrence concatenated as a single string in an array of Strings
|
|
206
|
206
|
*/ // TODO
|
|
207
|
207
|
public static String[] packConsecutiveDuplicates(String[] array) {
|
|
208
|
|
- String[] newArr = new String[array.length];
|
|
209
|
|
-
|
|
|
208
|
+
|
|
|
209
|
+ StringBuilder build = new StringBuilder(array[0]);
|
|
|
210
|
+
|
|
|
211
|
+ String[] newArr = new String[array.length-count(array)];
|
|
|
212
|
+ int counter = 0;
|
|
|
213
|
+ for(int i = 1; i<array.length; i++){
|
|
|
214
|
+ if(array[i-1].equals(array[i])){
|
|
|
215
|
+ build.append(array[i]);
|
|
|
216
|
+
|
|
|
217
|
+ }
|
|
|
218
|
+ else{
|
|
|
219
|
+ newArr[counter] = build.toString();
|
|
|
220
|
+ build.setLength(0);
|
|
|
221
|
+ build.append(array[i]);
|
|
|
222
|
+ counter++;
|
|
|
223
|
+ }
|
|
|
224
|
+ }
|
|
210
|
225
|
|
|
211
|
|
- return null;
|
|
|
226
|
+ newArr[counter] = build.toString();
|
|
|
227
|
+ return newArr;
|
|
|
228
|
+ }
|
|
|
229
|
+
|
|
|
230
|
+ public static int count(String[] array){
|
|
|
231
|
+ int count = 0;
|
|
|
232
|
+ for(int i = 1; i<array.length; i++){
|
|
|
233
|
+ if(array[i-1].equals(array[i])) {
|
|
|
234
|
+
|
|
|
235
|
+ count++;
|
|
|
236
|
+ }
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ return count;
|
|
212
|
240
|
}
|
|
213
|
241
|
|
|
214
|
242
|
}
|