-
Notifications
You must be signed in to change notification settings - Fork 0
new: added searching substrings with string[] with lambdas #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new problem (Q005) demonstrating string filtering with lambdas and Stream API. It introduces functionality to search for substrings within string arrays, comparing traditional loop-based approaches with Java 8 Stream API implementations.
Key changes:
- Added utility methods for string array generation and printing
- Implemented traditional and stream-based substring filtering examples
- Created comprehensive performance comparison with multiple dataset sizes (20 to 1M strings)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| ComparisonUtils.java | Added string sample data array and three utility methods: printStrings(), getStringArrayWithPatternAtEnd(), and getStringArray() |
| PrintStringsTraditional.java | Implements traditional for-loop approach for filtering strings by substring |
| PrintStringsStream.java | Implements Stream API approach with filter() and contains() for substring matching |
| PrintStringsComparison.java | Benchmarks both approaches with test cases ranging from 20 to 1,000,000 strings |
| README.md | Updated documentation to include Q005, new utility methods, and string operation concepts |
| PROBLEMS.md | Added Q005 problem statement and updated utility method documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| System.out.println("]\n"); | ||
| } | ||
|
|
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing JavaDoc documentation for the getStringArrayWithPatternAtEnd method. All other public methods in this class have JavaDoc comments with @param and @return tags.
| /** | |
| * Generates an array of strings of the specified size, with some elements containing the given pattern at the end. | |
| * @param size the number of strings to generate | |
| * @param pattern the pattern to append to some strings | |
| * @return an array of strings, some of which have the pattern appended at the end | |
| */ |
| if(str.contains(substring)) | ||
| System.out.print(str+","); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Missing braces for if statement. According to Java best practices, single-line if statements should include braces for better readability and maintainability. Should be:
if(str.contains(substring)) {
System.out.print(str+",");
}| if(str.contains(substring)) | |
| System.out.print(str+","); | |
| if(str.contains(substring)) { | |
| System.out.print(str+","); | |
| } |
| * 2. Print each string to the console. | ||
| */ | ||
| for (String str : strings) { | ||
| if(str.contains(substring)) |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after if keyword. Should be if (str.contains(substring)) with a space before the opening parenthesis, following Java style conventions.
| if(str.contains(substring)) | |
| if (str.contains(substring)) |
| .filter(n->n.contains(subString)) | ||
| .forEach(n->System.out.print(n+",")); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space in lambda expression arrow operator. Should be .filter(n -> n.contains(subString)) with spaces around the arrow operator for consistency with Java lambda style conventions.
| .filter(n->n.contains(subString)) | |
| .forEach(n->System.out.print(n+",")); | |
| .filter(n -> n.contains(subString)) | |
| .forEach(n -> System.out.print(n+",")); |
| .filter(n->n.contains(subString)) | ||
| .forEach(n->System.out.print(n+",")); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space in lambda expression arrow operator. Should be .forEach(n -> System.out.print(n+",")) with spaces around the arrow operator for consistency with Java lambda style conventions.
| .filter(n->n.contains(subString)) | |
| .forEach(n->System.out.print(n+",")); | |
| .filter(n -> n.contains(subString)) | |
| .forEach(n -> System.out.print(n+",")); |
| * Traditional approach to print all strings in an array. | ||
| * Steps: | ||
| * 1. Use a for-each loop to iterate through each string in the array. | ||
| * 2. Print each string to the console. |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misleading documentation comment. Step 2 states "Print each string to the console" but the method actually prints only strings that contain the specified substring. Update to: "2. Print strings that contain the substring to the console."
| * 2. Print each string to the console. | |
| * 2. Print strings that contain the substring to the console. |
|
|
||
| public static void main(String[] args) { | ||
| System.out.println("Q005: Print All Strings containing substring '_test' using Stream API"); | ||
| ComparisonUtils.repeat("-",80);; |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double semicolon detected on line 14. Remove the extra semicolon at the end of this line.
| ComparisonUtils.repeat("-",80);; | |
| ComparisonUtils.repeat("-",80); |
| //{"Apple_test", "Banana", "Cherry_test", "Date", "Elderberry", "Fig_test", "Grape", "Honeydew_test"}; | ||
| String subString = "_test"; | ||
|
|
||
| System.out.println("Input with length "+strings.length+": "); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after + operator. Should be "Input with length " + strings.length + ": " with spaces around the concatenation operators for consistency.
| System.out.println("Input with length "+strings.length+": "); | |
| System.out.println("Input with length " + strings.length + ": "); |
| searchStrings(strings, subString); | ||
| } | ||
|
|
||
|
|
||
| public static void searchStrings(String[] strings, String subString){ |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method naming inconsistency. In PrintStringsStream.java, the method is named searchStrings() while in PrintStringsTraditional.java, it's named printStrings(). Both methods have the same purpose (filtering and printing strings with a substring). For consistency and clarity, they should have the same name. Consider using printStringsWithSubstring() or filterAndPrintStrings() for both.
| searchStrings(strings, subString); | |
| } | |
| public static void searchStrings(String[] strings, String subString){ | |
| printStringsWithSubstring(strings, subString); | |
| } | |
| public static void printStringsWithSubstring(String[] strings, String subString){ |
| } | ||
| return result; | ||
| } | ||
|
|
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing JavaDoc documentation for the new printStrings method. All other public methods in this class have JavaDoc comments with parameter descriptions.
| /** | |
| * Prints the elements of a string array in a formatted manner. | |
| * @param strings the array of strings to print | |
| */ |
No description provided.