Git-Leon da16de6b83 Update README.md | 6 yıl önce | |
---|---|---|
src | 6 yıl önce | |
.gitignore | 6 yıl önce | |
README.md | 6 yıl önce | |
pom.xml | 6 yıl önce |
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)
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