Ad
  • Default User Avatar

    IntSummaryStatistics will do too much not needed operations (count, average, sum...), which would not be efficient at all on big lists.

    Thumbs up for using modern stream methods

  • Default User Avatar

    From my point of view, unless you have a prodigious mind, you need to use several times a function to remember it... and there is a lot oof objects an functions out there. So the best approach is to think if an object could have a function related to it that could be handy and search for it.
    However, sometimes if best try to think out of the box and try your best shoot and then see if there is that function out there.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Using streams for simple tasks like finding the maximum product of adjacent elements in an array is certainly a valid approach, and it can make your code look clean and concise. However, there are a few reasons why some developers might prefer using loops over streams for such tasks:

    1. Readability and Maintainability: While streams can make code look concise, they might not always be as readable as traditional loops, especially for more complex operations. For someone who is not familiar with streams, understanding the code might be more challenging. In contrast, loops often have a more straightforward and intuitive syntax.

    2. Performance Overhead: Streams can introduce some performance overhead compared to traditional loops. Streams have to perform additional operations such as creating an iterator, invoking the lambda function for each element, and handling the stream pipeline. For simple operations, like iterating through an array and performing a basic operation, the performance impact might be negligible. However, for performance-critical operations, loops could be more efficient.

    3. Learning Curve: While streams provide a powerful and expressive way to process collections, they also introduce a learning curve. Developers who are not familiar with streams might need to spend some time learning the concepts and best practices. Traditional loops, on the other hand, are more widely understood and easier to pick up for beginners.

    4. Debugging and Testing: Debugging and testing might be easier with traditional loops since you can easily add breakpoints, inspect variables, and step through the code. Streams, especially more complex ones, might make debugging more challenging.

    5. Code Reviews and Team Collaboration: In a team setting, it's important to consider the familiarity of your team members with certain coding styles. Using more commonly understood constructs, like traditional loops, can lead to better collaboration and code reviews.

    It's important to note that whether you choose to use streams or loops often depends on the context, the complexity of the operation, performance considerations, and the preferences and expertise of your development team. In many cases, both streams and loops have their place and can be used effectively.

  • Custom User Avatar

    tacticalcacti, use spoiler flag next time, please.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Default User Avatar

    Could anyone break down this regular expresion please.

  • Custom User Avatar

    very interesting and clever way to do this.

  • Default User Avatar

    Guys, can someone explain why is this solution not best practice? I mean rather in general, not exactly this one, but loops are better, than streams or what? Streams looks so neat.

  • Custom User Avatar

    It seems to me that returning Integer.MIN_VALUE is not the most obvious things that the method can do if it does not find the desired value. 0 or -1 would be more appropriate, IMHO :)

  • Custom User Avatar

    According to the condition of the problem, the length of the array is guaranteed to be > 1, in the examples it can be seen that the first element in the incoming array is "thrown out", this is logical, because checking for i % 0 will not make sense. That's why we start the sequence with 1

  • Custom User Avatar

    13 itself is an odd number.

  • Default User Avatar

    Thank you so much for explaining this! Your comment is super helpful.

    However, the statement 'A positive integer can be represented as a sum of consecutive integers if and only if it is divisible by an odd number' is not always true:
    13 is a sum of consecutive integers (6+7) and is not divisible by an odd number (this seems to apply to any prime number > 2 if fact)

  • Default User Avatar

    As I can understand you can just find those methods in the installed Java editors like IJ IDEA. They come handy when you need to find the specific methods of classes. Just typing, for instance, "str." it will show you every single method that class "str" has. Actually, in my opinion, it is the best way to practice. However, not all editors may provide the methods of classes. Sublime, of course is one of them. The only reason to use Sublime and such editors is that they are super fast.

  • Loading more items...