|
|
@@ -49,7 +49,6 @@ public class StringArrayUtils {
|
|
49
|
49
|
return false;
|
|
50
|
50
|
}
|
|
51
|
51
|
|
|
52
|
|
-
|
|
53
|
52
|
|
|
54
|
53
|
/**
|
|
55
|
54
|
* @param array of String objects
|
|
|
@@ -72,7 +71,7 @@ public class StringArrayUtils {
|
|
72
|
71
|
public static boolean isPalindromic(String[] array){
|
|
73
|
72
|
return (Arrays.equals(array, reverse(array)));
|
|
74
|
73
|
}
|
|
75
|
|
-
|
|
|
74
|
+
|
|
76
|
75
|
/**
|
|
77
|
76
|
* @param array array of String objects
|
|
78
|
77
|
* @return true if each letter in the alphabet has been used in the array
|
|
|
@@ -82,7 +81,7 @@ public class StringArrayUtils {
|
|
82
|
81
|
String alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
83
|
82
|
StringBuilder brokenStringArr = new StringBuilder();
|
|
84
|
83
|
for (String s : array){
|
|
85
|
|
- brokenStringArr.append(s);
|
|
|
84
|
+ brokenStringArr.append(s);
|
|
86
|
85
|
}
|
|
87
|
86
|
String newString = brokenStringArr.toString();
|
|
88
|
87
|
char [] toChar = newString.toCharArray();
|
|
|
@@ -91,6 +90,7 @@ public class StringArrayUtils {
|
|
91
|
90
|
}
|
|
92
|
91
|
return answer;
|
|
93
|
92
|
}
|
|
|
93
|
+
|
|
94
|
94
|
public static boolean contains(char[] array, char value) {
|
|
95
|
95
|
for(char s: array){
|
|
96
|
96
|
if (value == s)
|
|
|
@@ -98,7 +98,7 @@ public class StringArrayUtils {
|
|
98
|
98
|
}
|
|
99
|
99
|
return false;
|
|
100
|
100
|
}
|
|
101
|
|
-
|
|
|
101
|
+
|
|
102
|
102
|
/**
|
|
103
|
103
|
* @param array array of String objects
|
|
104
|
104
|
* @param value value to check array for
|
|
|
@@ -157,29 +157,31 @@ public class StringArrayUtils {
|
|
157
|
157
|
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
|
|
158
|
158
|
*/ // TODO
|
|
159
|
159
|
public static String[] packConsecutiveDuplicates(String[] array) {
|
|
160
|
|
- int j = 0;
|
|
161
|
160
|
int count = counterArray(array);
|
|
162
|
161
|
String [] newArray = new String [array.length-count];
|
|
163
|
|
-
|
|
164
|
|
- for(int x = 0; x < array.length-1; x++){
|
|
165
|
|
- if(array[x].equals(array[x+1])){
|
|
|
162
|
+ newArray[0] = array[0];
|
|
|
163
|
+ int j = 0;
|
|
|
164
|
+ String previous = array[0];
|
|
|
165
|
+ for (int x=1; x<array.length; x++){
|
|
|
166
|
+ if((array[x].equals(previous))){
|
|
166
|
167
|
newArray[j] += array[x];
|
|
167
|
168
|
}
|
|
168
|
|
- else
|
|
169
|
|
- newArray[j] = array[x];
|
|
170
|
|
- j++;
|
|
|
169
|
+ else{
|
|
|
170
|
+ newArray[j] = array[x];
|
|
|
171
|
+ previous = array[x];
|
|
|
172
|
+ j++;
|
|
|
173
|
+ }
|
|
171
|
174
|
}
|
|
172
|
175
|
return newArray;
|
|
173
|
176
|
}
|
|
174
|
|
-
|
|
175
|
|
-
|
|
|
177
|
+
|
|
176
|
178
|
public static int counterArray(String[] array) {
|
|
177
|
|
- int count = 0;
|
|
178
|
|
- for(int x = 0; x < array.length-1; x++){
|
|
|
179
|
+ int count = 0;
|
|
|
180
|
+ for(int x = 0; x < array.length-1; x++){
|
|
179
|
181
|
if (array[x].equals(array[x+1])){
|
|
180
|
182
|
count++;
|
|
181
|
183
|
}
|
|
182
|
184
|
}
|
|
183
|
|
- return count;
|
|
184
|
|
-}
|
|
|
185
|
+ return count;
|
|
|
186
|
+ }
|
|
185
|
187
|
}
|