|
|
@@ -42,7 +42,7 @@ public class StringArrayUtils {
|
|
42
|
42
|
* @return true if the array contains the specified `value`
|
|
43
|
43
|
*/ // TODO
|
|
44
|
44
|
public static boolean contains(String[] array, String value) {
|
|
45
|
|
- return Arrays.asList(array).contains(value);
|
|
|
45
|
+ return Arrays.asList(array).contains(value);
|
|
46
|
46
|
}
|
|
47
|
47
|
|
|
48
|
48
|
/**
|
|
|
@@ -71,12 +71,19 @@ public class StringArrayUtils {
|
|
71
|
71
|
* @return true if each letter in the alphabet has been used in the array
|
|
72
|
72
|
*/ // TODO
|
|
73
|
73
|
public static boolean isPangramic(String[] array) {
|
|
74
|
|
- String[] alpha = "abcdefghijklmnopqrstuvwxyz".split("");
|
|
75
|
|
- System.out.println(alpha);
|
|
|
74
|
+ String[] alpha = {"a","b","c","d","e","f","g","h","i","j",
|
|
|
75
|
+ "k","l","m","n","o","p","q","r","s","t",
|
|
|
76
|
+ "u","v","w","x","y","z"};
|
|
|
77
|
+ String result = "";
|
|
|
78
|
+ int count = 0;
|
|
|
79
|
+ for (String e : array) {
|
|
|
80
|
+ result += e.replace(" ", "");
|
|
|
81
|
+ }
|
|
|
82
|
+ String[] check = result.toLowerCase().split("");
|
|
76
|
83
|
for (String letter : alpha) {
|
|
77
|
|
- if(!contains(array, letter)) return false;
|
|
|
84
|
+ if (contains(check, letter)) count++;
|
|
78
|
85
|
}
|
|
79
|
|
- return true;
|
|
|
86
|
+ return count == alpha.length;
|
|
80
|
87
|
}
|
|
81
|
88
|
|
|
82
|
89
|
/**
|
|
|
@@ -98,18 +105,24 @@ public class StringArrayUtils {
|
|
98
|
105
|
* @return array with identical contents excluding values of `value`
|
|
99
|
106
|
*/ // TODO
|
|
100
|
107
|
public static String[] removeValue(String[] array, String valueToRemove) {
|
|
101
|
|
- String[] result = array.toString()
|
|
102
|
|
- .replaceAll(valueToRemove, "")
|
|
103
|
|
- .split("");
|
|
104
|
|
- return result;
|
|
|
108
|
+ ArrayList<String> result = new ArrayList<>();
|
|
|
109
|
+ for (String s : array) {
|
|
|
110
|
+ if (!s.equals(valueToRemove)) result.add(s);
|
|
|
111
|
+ }
|
|
|
112
|
+ return result.toArray(new String[result.size()]);
|
|
105
|
113
|
}
|
|
106
|
114
|
|
|
107
|
115
|
/**
|
|
108
|
116
|
* @param array array of chars
|
|
109
|
117
|
* @return array of Strings with consecutive duplicates removes
|
|
110
|
118
|
*/ // TODO
|
|
111
|
|
- public static String[] removeConsecutiveDuplicates(String[] array) {
|
|
112
|
|
- return null;
|
|
|
119
|
+ public static String[] removeConsecutiveDuplicates(String[] array) {
|
|
|
120
|
+ ArrayList<String> result = new ArrayList<>();
|
|
|
121
|
+ for (int i = 0; i < array.length - 1; i++) {
|
|
|
122
|
+ if (!array[i].equals(array[i + 1])) result.add(array[i]);
|
|
|
123
|
+ }
|
|
|
124
|
+ result.add(array[array.length - 1]);
|
|
|
125
|
+ return result.toArray(new String[result.size()]);
|
|
113
|
126
|
}
|
|
114
|
127
|
|
|
115
|
128
|
/**
|
|
|
@@ -117,7 +130,21 @@ public class StringArrayUtils {
|
|
117
|
130
|
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
|
|
118
|
131
|
*/ // TODO
|
|
119
|
132
|
public static String[] packConsecutiveDuplicates(String[] array) {
|
|
120
|
|
- return null;
|
|
|
133
|
+ ArrayList<String> result = new ArrayList<>();
|
|
|
134
|
+ StringBuilder addMe = new StringBuilder();
|
|
|
135
|
+ for (int i = 0; i < array.length - 1; i++) {
|
|
|
136
|
+ if (!array[i].equals(array[i + 1])) {
|
|
|
137
|
+ addMe.append(array[i]);
|
|
|
138
|
+ result.add(addMe.toString());
|
|
|
139
|
+ addMe = new StringBuilder();
|
|
|
140
|
+ }
|
|
|
141
|
+ else {
|
|
|
142
|
+ addMe.append(array[i]);
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
|
145
|
+ addMe.append(array[array.length - 1]);
|
|
|
146
|
+ result.add(addMe.toString());
|
|
|
147
|
+ return result.toArray(new String[result.size()]);
|
|
121
|
148
|
}
|
|
122
|
149
|
|
|
123
|
150
|
|