|
|
@@ -145,26 +145,41 @@ public class StringArrayUtils {
|
|
145
|
145
|
return revisedArray;
|
|
146
|
146
|
}
|
|
147
|
147
|
|
|
|
148
|
+ public static String[] sortArray(String[] array){
|
|
|
149
|
+ String[] sorted = new String[array.length];
|
|
|
150
|
+ Arrays.sort(sorted);
|
|
|
151
|
+ return sorted;
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
148
|
154
|
/**
|
|
149
|
155
|
* @param array array of chars
|
|
150
|
156
|
* @return array of Strings with consecutive duplicates removes
|
|
151
|
157
|
*/ // TODO
|
|
152
|
158
|
public static String[] removeConsecutiveDuplicates(String[] array) {
|
|
153
|
|
-
|
|
154
|
|
- for(int i = 0; i < array.length-2; i++){
|
|
155
|
|
- if (array[i].equals(array[i+1])){
|
|
156
|
|
- array[i+1]= null;
|
|
157
|
|
- }
|
|
|
159
|
+ int dupes = countDuplicates(array);
|
|
|
160
|
+ String[] revisedArr = new String[array.length-dupes];
|
|
|
161
|
+ int j = 0;
|
|
|
162
|
+ for(int i = 0; i < array.length-1; i++){
|
|
|
163
|
+ if (array[i]!=(array[i+1])){
|
|
|
164
|
+ revisedArr[j] = array[i];
|
|
|
165
|
+ j++;
|
|
|
166
|
+ }
|
|
158
|
167
|
}
|
|
159
|
|
- removeValue(array, null);
|
|
160
|
|
- return array;
|
|
|
168
|
+ revisedArr[revisedArr.length-1]=array[array.length-1];
|
|
|
169
|
+ return revisedArr;
|
|
161
|
170
|
}
|
|
162
|
171
|
|
|
163
|
|
- public static String[] sortArray(String[] array){
|
|
164
|
|
-
|
|
165
|
|
-
|
|
|
172
|
+ public static int countDuplicates(String[] array){
|
|
|
173
|
+ String[] newArray = array;
|
|
|
174
|
+ int counter = 0;
|
|
|
175
|
+ for(int i = 0; i < newArray.length-1; i++){
|
|
|
176
|
+ if (newArray[i].equals(newArray[i+1])){
|
|
|
177
|
+ counter++;
|
|
|
178
|
+ }
|
|
|
179
|
+ }
|
|
|
180
|
+ return counter;
|
|
166
|
181
|
}
|
|
167
|
|
-
|
|
|
182
|
+
|
|
168
|
183
|
/**
|
|
169
|
184
|
* @param array array of chars
|
|
170
|
185
|
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
|