Git-Leon cf957d007e Update README.md | 6 gadus atpakaļ | |
---|---|---|
src | 6 gadus atpakaļ | |
.gitignore | 6 gadus atpakaļ | |
README.md | 6 gadus atpakaļ | |
pom.xml | 6 gadus atpakaļ |
Objective
int getNumberOfOccurrences(String[] stringArray, String stringToCheck)
boolean contains(String[] stringArray, String stringToCheck)
String[] removeValue(String[] stringArray, String stringToRemove)
Purpose
StringArrayUtils.removeValues(array, valueToRemove)
String
objects named array
and a String
object named valueToRemove
valueToRemove
. Ensure that the length of the newly created array has been resized based on the removal of the undesired elements.
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
String[] actual = StringArrayUtils.removeValues(array, "aba");
// : Then
System.out.println(Arrays.toString(actual));
Sample Output
[baa, bab, bba, bba, bba, bba, bbb, bbb};
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
String[] actual = StringArrayUtils.removeValues(array, "bba");
// : Then
System.out.println(Arrays.toString(actual));
Sample Output
[aba, aba, baa, bab, bbb, bbb];
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
String[] actual = StringArrayUtils.removeValues(array, "bbb");
// : Then
System.out.println(Arrays.toString(actual));
Sample Output
[aba, aba, baa, bab, bba, bba, bba, bba];
StringArrayUtils.getNumberOfOccurrences(array, value)
String
objects named array
and a String
object named value
value
appears in arrays
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bba");
// : Then
System.out.println(numberOfOccurrences);
Sample Output
4
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "bbb");
// : Then
System.out.println(numberOfOccurrences);
Sample Output
2
Sample Script
// : Given
String[] array = {"aba", "aba", "baa", "bab", "bba", "bba", "bba", "bba", "bbb", "bbb"};
// : When
int numberOfOccurrences = StringArrayUtils.getNumberOfOccurrences(array, "baa");
// : Then
System.out.println(numberOfOccurrences);
Sample Output
1
StringArrayUtils.contains(array, value)
Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
boolean outcome = StringArrayUtils.contains(array, "the");
// : Then
System.out.println(outcome);
Sample Output
true
Sample Script
// : Given
String[] array = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
// : When
boolean outcome = StringArrayUtils.contains(array, "potatoes");
// : Then
System.out.println(outcome);
Sample Output
false