Git-Leon cf957d007e
Update README.md
6 anni fa
src first commit 6 anni fa
.gitignore first commit 6 anni fa
README.md Update README.md 6 anni fa
pom.xml first commit 6 anni fa

README.md

Building Utility Class for String Array Objects

  • Objective

    • To complete the utility methods in the class [StringArrayUtils]()
      • int getNumberOfOccurrences(String[] stringArray, String stringToCheck)
      • boolean contains(String[] stringArray, String stringToCheck)
      • String[] removeValue(String[] stringArray, String stringToRemove)
  • Purpose

    • To establish greater familiarity with loops and arrays.
    • To demonstrate the implementation of a Utility class





Sample Behavior
StringArrayUtils.removeValues(array, valueToRemove)

  • Description
    • Given an array of String objects named array and a String object named valueToRemove
      create and return an array containing identical contents excluding objects whose value is equivalent to valueToRemove. Ensure that the length of the newly created array has been resized based on the removal of the undesired elements.

Example 1

  • 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};
    

Example 2

  • 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];
    

Example 3

  • 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];
    





Sample Behavior
StringArrayUtils.getNumberOfOccurrences(array, value)

  • Method Description
    • Given an array of String objects named array and a String object named value
      return the number of times value appears in arrays

Example 1

  • 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
    

Example 2

  • 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
    

Example 3

  • 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
    





Sample Behavior
StringArrayUtils.contains(array, value)

Example 1

  • 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
    

Example 2

  • 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