Ad
  • Default User Avatar

    I used & but I then realized it should be &&

  • Custom User Avatar
  • Custom User Avatar

    Indeed, but in this kind of pb, I like person using overwhelming magic ! :D

  • Default User Avatar

    I could be wrong, but doesn't this solution run through every character in the String? Would a solution that iterates through the String's characters and ends after finding two identical characters be more efficient?

  • 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 :)

  • Loading more items...