Ad
  • Default User Avatar

    This is still O(array1.length * array2.length) - just as yours.
    Replacing loops with streams is not taking away complexity.

  • Default User Avatar

    Yes it is. The list after the filtering is not gauranteed to be sorted.

  • Default User Avatar

    See my reply john777

  • Default User Avatar

    Cool so to explain the filter function a little. The filter function takes in a function that returns TRUE or FALSE. The inner lambda expression (as a whole) returns a boolean VALUE (Arrays.stream(array2).anyMatch(s -> s.contains(str)).

    For example I can write
    boolean matchedResult = memberNames.stream().anyMatch((s) -> s.startsWith("filtered-strings-have-this-text"));

    Notice again that matchedResults is of a boolean type, although anyMatch takes in a function as an argument, it returns a definate answer. (true or false)

    The magic happens because this value (str) in the filter function satisfies the condition f(str) -> True or False.

    Took me a little while to wrap my head around that ... coming frm a 1.7 world.

    Guys, remember that this solution is better than all other solutions because it's complexity is on a smaller order. Other solutions AFAIK are on an order of O(n^2) including mine.