Git-Leon afc9785d65 Update README.md | пре 6 година | |
---|---|---|
src | пре 6 година | |
.gitignore | пре 6 година | |
README.md | пре 6 година | |
pom.xml | пре 6 година |
Objective
int getNumberOfOccurrences(String[] stringArray, String stringToCheck)
boolean contains(String[] stringArray, String stringToCheck)
String[] removeValue(String[] stringArray, String stringToRemove)
Purpose
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];
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
contains(array, value)
Description
Given an array of String
objects named array
and a String
object named value
return true if value
appears in arrays
.
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